solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e9 + 7;
const int N = (int)1e5 + 4;
const int M = 1005;
const int K = 25;
int main() {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; ++i) {
int a, k;
scanf("%d %d", &k, &a);
if (a == 1) {
ans = max(an... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long f[1000006][21];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
memset((f), (-1), sizeof(f));
while (t--) {
long long n, m;
cin >> n >> m;
char a[n][m];
char b[n * m];
for (int i = 0, ggdem = ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, dmo, dpo;
cin >> n;
long long cntneg = 0, cntzero = 0, cost = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == 0) {
cntzero++;
continue;
}
if (a < 0) cntneg++;
dmo = abs(a + 1);
dpo = abs(a - 1);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
long double Dis(long long a, long long Y, long long b, long long YY) {
return sqrt((long double)(b - a) * (b - a) + (Y - YY) * (Y - YY));
}
struct PT {
long long ID;
long double len, Y;
PT(long long _ID, long double _Y) {
ID = _ID;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16;
const int maxn = 1010;
const int maxm = 10010;
struct edge {
int v, w;
edge(int v, int w) : v(v), w(w) {}
edge() {}
};
int u[maxm];
int pu[maxm];
int v[maxm];
int pv[maxm];
int w[maxm];
bool flag[maxm];
vector<edge> E[maxn];
void addEdge(in... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k;
cin >> n;
vector<pair<long long, long long>> pris(n);
for (i = 0; i < n; i++) {
cin >> j >> k;
pris[i] = make_pair(k, j);
}
cin >> j;
vector<long long> p(j + 1);
for (i = 0; i < j; i++) cin >> p[i];
p[j] = 1111111111111... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 109;
int t;
int n, m;
char a[MAXN][MAXN];
int main() {
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i] + 1;
int ans_1 = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j ... | 7 |
#include <bits/stdc++.h>
int main() {
int n, p = 0, t = 0;
std::cin >> n;
std::string s;
std::cin >> s;
for (int i = 0; i < s.size() - 1; ++i) {
if (s[i] == 'S' && s[i + 1] == 'F')
++p;
else if (s[i] == 'F' && s[i + 1] == 'S')
++t;
}
if (p > t)
std::cout << "YES";
else
std::c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NR = 1e5 + 10;
void Min(int& x, int y) { x = min(x, y); }
void Max(int& x, int y) { x = max(x, y); }
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && c... | 11 |
#include <bits/stdc++.h>
using namespace std;
int r, s, p;
double dp[101][101][101];
int main() {
cin >> r >> s >> p;
memset(dp, 0, sizeof(dp));
dp[r][s][p] = 1.0;
for (int i = r; i >= 0; i--) {
for (int j = s; j >= 0; j--) {
for (int k = p; k >= 0; k--) {
double sum = i * j + j * k + k * i;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, s, i, j, x, y, z, a, b, c, aa, ab, ac, ans, cnt;
int main() {
cin >> n >> s;
for (i = 1; i <= n; i++) {
cin >> j;
if (j == 3) x++;
if (j == 4) y++;
if (j == 5) z++;
}
n = x + y + z;
ans = 0x3fffffff;
for (a = s / n; a >= 0; a--)
for (b... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5;
const int oo = 1e9;
int ans[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
if (n == 1 && k == 0) {
cout << "yes 0\n";
return 0;
}
int nini = n;
if (n % 2 == 0 || k >= ... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<int> factors(int x) {
vector<int> f;
for (long long i = 2; i * i <= x; i++) {
if (x % i == 0) {
f.push_back(i);
if (i * i != x) {
f.push_back(x / i);
}
}
}
return f;
}
int main() {
ios_base::sync_with_stdio(false);
int p,... | 6 |
#include <bits/stdc++.h>
long long m[150000];
int main() {
int n, a, b;
while (scanf("%d%d%d", &n, &a, &b) != EOF) {
int i;
for (i = 0; i < n; i++) scanf("%I64d", &m[i]);
for (i = 0; i < n; i++) {
long long c, d;
c = (m[i] * a) / b;
d = (c * b) / a;
if (!((d * a) / b == c)) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ans;
int a[60][30050], s[60][30050];
int lmax[30050], rmax[30050];
int dp[30050], newdp[30050];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> a[i][j... | 15 |
#include <bits/stdc++.h>
using namespace std;
int N;
long long K;
long long divide[60] = {0};
int ans[60] = {0};
int main() {
cin >> N >> K;
divide[0] = 1;
divide[1] = 1;
for (int i = 1; i <= N; i++) ans[i] = i;
for (int i = 2; i <= N; i++) divide[i] = divide[i - 2] + divide[i - 1];
for (int i = 1; i < N; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 16, inf = INT_MAX / 2;
int N, M, g[maxN][maxN], sl[1 << 15][maxN][maxN], dp[1 << 15], tr[1 << 15],
ss[1 << 15], ee[1 << 15];
int fm;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
fm = (1 << N) - 1;
for... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mxn = 1e5 + 10;
int pw[mxn], pw2[mxn];
int check(long long x) {
if (x >= mod) return x % mod;
return x;
}
int expo(int a, int n) {
int ret = 1;
while (n) {
if (n & 1) ret = check(1LL * ret * a);
a = check(1LL * a * a);
... | 9 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define all(x) (x).begin(),(x).end()
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define sz(x) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v;
} e[400005];
int head[200005], nxt[400005], cnt;
void addnode(int u, int v) {
e[++cnt] = (edge){u, v};
nxt[cnt] = head[u];
head[u] = cnt;
}
int siz[200005], fa[200005], n;
long long dp[200005], ans;
void dfs(int u) {
siz[u] = 1;
for (int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char board[3][3];
int i, j;
int xnum = 0, onum = 0, dnum = 0;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
cin >> board[i][j];
if (board[i][j] == 'X') xnum++;
if (board[i][j] == '0') onum++;
if (board[i][j] == '.') dnu... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
int a[maxn];
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int t, flag = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] == 1) t = i;
a[i + n] = a[i];
}
if (n == 1) {
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
int arr[n][n];
int flag = 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> arr[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (arr[i][j] != 1) {
... | 0 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
using ll = long long;
const ll n_ = 300300, inf = 1e18;
ll n, m, a, b, c, d, t, x, y, base = 1;
ll tree[n_ * 4][2], psum[n_], k;
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define x first
#define y second
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x,T y){x<y?x=y:T();}
template <typename T> void chkmin(T &x,T y){y<x?x=y:T();}
te... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
cout << "2"
<< " " << n - 1 << endl;
}
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + ... | 16 |
#include <bits/stdc++.h>
using namespace std;
char g[1000 + 1][1000 + 1];
int INF = INT_MAX / 3;
inline void connect(int v1, int v2) {
g[v1][v2] = 'Y';
g[v2][v1] = 'Y';
}
int main() {
ios_base::sync_with_stdio(false);
unsigned int k;
cin >> k;
int leng = 0;
for (int i = 0; i < 1000; i++) {
for (int j ... | 11 |
#include <bits/stdc++.h>
using namespace std;
class C_ {};
template <typename T>
C_& operator<<(C_& __m, const T& __s) {
if (!1) cerr << "\E[91m" << __s << "\E[0m";
return __m;
}
C_ merr;
struct __s {
__s() {
if (1) {
ios_base::Init i;
cin.sync_with_stdio(0);
cin.tie(0);
}
}
~__s() {... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct tree {
int a, h;
double pl, pr;
};
struct mushroom {
int b, z;
};
tree tr[500010];
mushroom mr[500010];
int X[500010], cntx;
double tree[500010 << 2];
void build(int L, int R, int rt) {
tree[rt] = 1;
if (L != R) {
int mid = (L + R) >> 1;
build(L, mi... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
struct UnionFind {
vector<int> data;
void init(int n) { data.assign(n, -1); }
bool unionSet(int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int Q;
bool vis[41];
int C;
map<string, int> msi;
int N;
int DP[1 << 23];
long long V[41];
int dp(long long S) {
if (S < (1LL << 23) && DP[S] != -1) return DP[S];
bool fnd = false;
int u;
for (int i = 0; i <= N - 1; i++)
if (S & (1LL << i)) {
fnd = true;
... | 14 |
#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
n >>= 1;
}
return (long long)ret;
}
using namespace std;
using namespace std;
vector<pair<int, int> > G;
void solv... | 8 |
#include <bits/stdc++.h>
using namespace std;
void fr(int &a, bool f = 0, char ch = getchar()) {
for (a = 0; ch < '0' || ch > '9'; ch = getchar()) ch == '-' ? f = 1 : 0;
for (; ch >= '0' && ch <= '9'; ch = getchar()) a = a * 10 + ch - '0';
a = f ? -a : a;
}
int fr() {
int a;
return fr(a), a;
}
const int N = 1... | 23 |
#include <bits/stdc++.h>
using namespace std;
bool x[1000007];
int main() {
int i, n, m, a, b, t = 0, c = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a;
t += a;
x[t] = 1;
}
t = 0;
for (int j = 0; j < m; j++) {
cin >> a;
t += a;
if (x[t]) c++;
}
cout << c;
return 0;
}... | 3 |
#include <bits/stdc++.h>
const long long MOD = (long long)1e9 + 7;
using namespace std;
long long power(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) return 1LL * power(a, b / 2) * power(a, b / 2);
b--;
return 1LL * power(a, b) * a;
}
int left(int i) { return 2 * i; }
int right(int i) { retu... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string str;
cin >> str;
queue<string> q;
set<string> s;
int ans = 0;
q.push(str);
s.insert(str);
while (!q.empty()) {
string curr = q.front();
q.pop();
ans += n - curr.size();
k--;
if (k == 0) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 20;
int n, m, k, h[500];
;
char a[mxn];
long long atol2(char s[]) {
long long q = 0;
for (int i = 0; i < strlen(s); i++)
if (isdigit(s[i])) q = q * 10 + s[i] - '0';
return q;
}
int main() {
ios_base::sync_with_stdio(false);
cin >> a;
h['a'] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
using ll = long long;
const int mod = 1e9 + 7;
struct mint {
int x;
mint operator+(mint b) {
return mint{x + b.x >= mod ? x + b.x - mod : x + b.x};
}
mint operator*(mint b) { return mint{int((ll)x * b.x % mod)}; }
mint pwr(int e) {
m... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j;
long long int p[60], prz[6], cnt[6], rest;
int main() {
cin >> n;
for (i = 1; i <= n; i++) cin >> p[i];
for (i = 1; i <= 5; i++) cin >> prz[i];
for (i = 1; i <= n; i++) {
rest += p[i];
for (j = 5; j >= 1; j--) {
if (prz[j] <= rest) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0;
int neg;
while (true) {
char ch = getchar();
if (ch >= '0' && ch <= '9' || ch == '-') {
if (ch == '-')
neg = -1;
else
neg = 1, res = ch - '0';
break;
}
}
while (true) {
char ch = ge... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long fact[800005], n, c;
long long p(long long x, long long y) {
if (y == 0) return 1 % 1000003;
if (y == 1) return x % 1000003;
if (y % 2) return p(x, y - 1) * x % 1000003;
long long z = p(x, y / 2);
return z * z % 1000003;
}
int main() {
fact[0] = 1;
fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000007, inf = 0x3f3f3f3f;
struct bit {
vector<int> seg;
bit() {}
bit(int n) { seg.assign(n + 5, 0); }
int query(int p) {
int ans = 0;
for (p++; p > 0; p -= p & -p) {
ans += seg[p];
}
return ans;
}
int query(int l, int r) { re... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> edges[200001];
vector<long long int> c(200001);
long long int ANS = 1;
void dfs(long long int i, long long int parent) {
long long int k = 1;
for (long long int j : edges[i]) {
if (j != parent) {
for (; k <= 200001; k++)
if (k != ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int start, stop, val;
char s[1000];
struct info {
int mn, p;
} tree[4 * 200005];
void Build(int n, int b, int e) {
if (b == e) {
tree[n].mn = a[b];
tree[n].p = 0;
return;
}
int l = n * 2;
int r = n * 2 + 1;
int m = (b + e) / 2;
Build... | 14 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minheap = priority_q... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > gr(1e5 + 1);
vector<int> BFS(int src) {
vector<int> dist(gr.size(), 1e9);
queue<int> q;
q.push(src);
dist[src] = 0;
while (!q.empty()) {
int v = q.front();
q.pop();
for (int i = 0; i < gr[v].size(); i++) {
int u = gr[v][i];
... | 12 |
#include <bits/stdc++.h>
const int maxn = 1e2 + 10;
using namespace std;
struct node {
int l, r;
node() {
l = 0;
r = 0;
}
} a[maxn];
int idx[maxn];
int Find(int n) {
if (a[n].r) {
return Find(a[n].r);
} else
return n;
}
int main() {
int n;
while (~scanf("%d", &n)) {
int l, r;
int c... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 326;
vector<int> adj[maxN];
deque<int> ord;
int N, M, u, v, x, deg[maxN], pa[maxN], root, minVal[maxN][2], maxDist[maxN][2];
bool is[maxN], cand[maxN];
void getPa(int p = root, int u = root) {
for (int v : adj[u])
if (v != p) {
pa[v] = u;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int arr[150];
int main() {
long long n, num;
cin >> n;
vector<long long> v;
for (int i = 0; i < n; i++) {
cin >> num;
v.push_back(num);
}
sort(v.begin(), v.end());
arr[1] = 1;
int c = 1, prev = v[0], ans = 0;
for (int i = 1; i < v.size(); i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
bool check[N];
int tot[N];
int main() {
int n, x;
cin >> n;
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
tot[x]++;
}
int now, ans = 1;
... | 6 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll N = 2e5 + 5, mod = 1e9 + 7;
const ll inf = 1e18;
struct cmp {
bool operator()(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
};
ll power(ll x, ll p) {
ll r = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, ans = (long long)1E9;
long long a[300];
vector<pair<long long, pair<long long, vector<long long> > > > V;
vector<long long> opt;
bool visit[300];
map<pair<long long, long long>, long long> M;
long long cmp, now;
void solve() {
long long tot = 0, temp = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using T = tuple<int, int, int>;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <type... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int pos = 0, r = 0;
while (1) {
if (pos == n) {
pos = 0;
}
if (arr[pos] - r <= 0) {
cout << pos + 1;
break;
} else {
r++;
... | 5 |
#include <bits/stdc++.h>
int n;
char s[100100];
int main() {
int i, j, k, m;
scanf("%s", s + 1);
n = strlen(s + 1);
for (i = 1; i + i <= n; ++i) {
k = 0;
m = i;
for (j = i + 1; j <= n; ++j) {
if (s[j] == s[j - i])
++k;
else
k = 0;
if (k == i) {
k = 0;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, t, k, x[(int)1e6], i, s;
int main() {
cin >> n;
for (i = 0; i < n; i++) cin >> x[i];
sort(x, x + n), n = unique(x, x + n) - x;
cin >> a >> b;
while (a > b) {
k = a - 1;
for (i = 0; i < n; i++)
if ((s = a - a % x[i]) < b)
x[i--] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
string A[100000 + 5], s;
int val[10], fact[10];
int n;
int main() {
cin >> s >> n;
for (int i = 0; i < n; ++i) {
cin >> A[i];
}
for (int i = 0; i < 10; ++i) {
val[i] = i, fact[i] = 10;
}
for (int i = n - 1; i >= 0; i--) {
int d = A[i][0] - '0';
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > V[303];
int mp[12][12];
long long inf;
int n;
int ha(int a, int b) { return b + a * 100; }
bool check(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= n; }
void add(int a, int b) { V[a].push_back(make_pair(b, 1)); }
pair<int, int> dis[303][3... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100010;
const int MaxK = 6;
const int MOD = 1000000007;
int n, m;
int a[MaxN];
long long s[MaxN][MaxK];
long long C[MaxK][MaxK];
long long power(long long x, long long y) {
if (!y) return 1;
long long t = power(x, y >> 1);
t = t * t % MOD;
if (y & 1... | 17 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, n, i;
scanf("%d", &n);
c = (n - 1) * (n - 1) + ((n - 1) + 1) * ((n - 1) + 1);
printf("%d", c);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int64_t, int64_t> get_best(
int node, int parent, const vector<vector<pair<int, int64_t>>> &adj_list,
const int64_t k) {
vector<pair<int64_t, int64_t>> child_results;
child_results.reserve(adj_list[node].size());
for (const auto neigh : adj_list[node]) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - 48;
ch = getchar();
}
}
int main() {
long long n, q;
read(n);
read(q);
while (q--) {
long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int magnets[n];
int groups = 1;
for (int i = 0; i < n; i++) {
cin >> magnets[i];
if (i != 0) {
if (magnets[i] != magnets[i - 1]) {
groups++;
}
}
}
cout << groups;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<vector<char>> a(N + 2, vector<char>(M + 2, '*'));
for (int i = 1; i < N + 1; ++i) {
scanf("\n");
for (int j = 1; j < M + 1; ++j) {
scanf("%c", &a[i][j]);
}
}
auto get_int = [&](int i, int j) -> int {... | 16 |
#include <bits/stdc++.h>
using namespace std;
int tx[8] = {1, 2, 2, 1, -1, -2, -2, -1}, ty[8] = {2, 1, -1, -2, -2, -1, 1, 2},
d1[2010][2010], d2[2010][2010], n, m;
struct no {
int x, y;
};
queue<no> q;
void bfs(int x, int y, int d[][2010]) {
q.push((no){x, y});
d[x][y] = 0;
while (!q.empty()) {
no x = q... | 21 |
#include <bits/stdc++.h>
using namespace std;
int N;
int A[100010] = {0};
int B[100010] = {0};
int id[100010] = {0};
int F[100010] = {0};
bool cmp(int a1, int a2) { return A[a1] < A[a2]; }
int Find(int k) {
int returnd = 0;
for (int l = 1, r = N; l <= r;) {
int mid = (l + r) >> 1;
if (A[id[mid]] < k) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e3 + 9;
long long n, m, mat[N][N], dp1[N][N], dp2[N][N], dp3[N][N], dp4[N][N], ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%lld",... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int s = 1000 * 1000;
int n;
bool numbers[s + 1];
vector<int> sol;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
numbers[tmp] = 1;
}
vector<int> z;
int kam = 0;
for (int i = 1; i <= s / 2; i++) {
if (numbers[i] ==... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
scanf("%d%d", &n, &k);
int kk = 0;
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j) ++kk;
if (n * (n - 1) / 2 <= k) {
printf("no solution\n");
return 0;
}
for (int i = 0; i < n; ++i) printf("%d %d\n", 0, i);
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INF_LL = 1000000000000000000LL;
const int h = 100011;
int n, a[h];
int main() {
scanf("%d", &n);
for (int i(0), _b(n); i < _b; ++i) scanf("%d", a + i);
long long ans = 0;
for (int k(0), _b(n - 1); k < _b; ++k) {
int t ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k, last = 0, ans = 0, x;
cin >> n >> k;
for (long long int i = 0; i < n; i++) {
cin >> x;
if (i == n - 1) {
last += x;
ans += ceil((long double)(la... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
int a[100100];
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int cnt = 0;
for (int i = 1; i < n; i++)
if (a[i - 1] == a[i]) {
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int getint() {
int x, c;
for (; !isdigit(c = getchar());)
;
for (x = c - '0'; isdigit(c = getchar()); x = x * 10 + c - '0')
;
return x;
}
const int N = 400000;
int n, a, b, c, d, len, t[N], q[N];
long long sg, st, mn;
int main() {
n = getint();
a ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int nr, N, M, a[89][89], cod[89][89], b[89][89];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
class MaxFlowMinCost {
public:
int N, M, S, D, ap[7009], t[7009], bell[7009], in_q[7009];
int F[60009], C[60009], bani[60009], X[60009], Y[60009];
vector<int> v[60009... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[1007][107][2];
int n, k, mod, pw;
int main() {
cin >> n >> k >> mod;
dp[0][0][0] = pw = 1;
for (int i = 0; i < n; i++) {
for (int rem = 0; rem < k; rem++) {
for (int was = 0; was < 2; was++) {
if (dp[i][rem][was]) {
for (int d = (i =... | 14 |
#include <bits/stdc++.h>
using namespace std;
char s[110000];
int n, f[110000], num[110000];
int bit1[110000], bit2[110000];
int query1(int x) {
int ans = 0;
while (x) {
ans = max(ans, bit1[x]);
x -= ((x) & (-(x)));
}
return ans;
}
void update1(int x, int newv) {
while (x <= n) {
bit1[x] = max(bit... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
string s = to_string(n);
long long int sz = s.length();
if (sz == 1) {
cout << n << endl;
return;
}
long long int arr[10] = {0, 9, 18, 27, 36, 45, 54, 63, 72, 81};
long long int cnt = 0;
long long int ok = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int power(long long int a, long long int b) {
long long int value = 1;
while (b) {
if (b & 1) {
value *= a;
}
a *= a;
b /= 2;
}
return value;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int a[maxn];
long long dpl[maxn][2], dpr[maxn][2];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) scanf("%d", &a[i]);
dpl[0][0] = dpl[0][1] = 0;
for (int i = 1; i < n; i++) {
if (a[i - 1] & 1) {
dpl[i][0] = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
int main() {
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
if (a <= b) {
long long res = 0;
long long temp = a - 1;
res = (temp) * (temp + 1) / 2;
cout << res + 1 << endl;
} ... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
stack<int> stk;
int pr[100005], bg[100005], lSol, rSol, maxim = -1;
int main() {
cin >> s;
int lgt = s.length();
for (int i = 0; i < lgt; i++) {
pr[i] = pr[i - 1];
if (s[i] == '[') pr[i]++;
bg[i] = -1;
}
for (int i = 0; i < lgt; i++) {
if... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct tree {
int v, mark;
tree *ls, *rs;
} T[1200006];
int N, Q, cnt, qry[300005][3];
int idx[600005], cni;
tree *root;
tree *new_tree() { return T + cnt++; }
tree *build(int l, int r, tree *t) {
if (l + 1 == r) {
t->v = idx[r] - idx[l];
t->mark = 0;
retu... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int p = 1000000007;
long long f[1001], d[1000001];
long long mul(long long x, int y) {
if (y == 0) return 1;
if (y == 1) return x;
long long z = mul(x, y / 2);
z = (z * z) % p;
if (y % 2 == 1) z = (z * x) % p;
return z;
}
long long c(int x, int y) { return... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double pi =
3.14159265358979323846264338327950288419716939937510582097494459230;
long long powm(long long a, long long b, long long m) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
int* arr = new int[n];
for (int i = 0; i < n - k; i++) arr[i] = i + 1;
int p = 0;
for (int i = n - k; i < n; i++, p++) {
if (p % 2 == 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int res = 0;
bool zf = 0;
char c;
while (((c = getchar()) < '0' || c > '9') && c != '-')
;
if (c == '-')
zf = 1;
else
res = c - '0';
while ((c = getchar()) >= '0' && c <= '9')
res = (res << 3) + (res << 1) + c - '0';
retur... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100 + 10;
long long n, m, k, x, y;
long long ans[MAX_N][MAX_N];
int main() {
cin >> n >> m >> k >> x >> y;
if (n == 1) {
long long a = k / m;
long long b = k % m;
cout << a + min(1ll, b) << " " << a << " ";
if (y <= b) {
cout << a... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, cor = 0;
cin >> n >> k;
vector<long long> A;
A.resize(n);
for (long long i = 0; i < n; i++) {
cin >> A[i];
}
for (long long i = 1; i <= n + 1; i++) {
if (i * (i + 1) / 2 >= k) {
k = k - (i - 1) * i / 2;
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 202202;
int n, m, T;
double c;
long long a[Max], p[Max];
double mean[Max];
int main() {
scanf(" %d %d %lf", &n, &T, &c);
for (int i = 1; i <= n; i++) scanf(" %I64d", &a[i]);
p[0] = 0;
for (int i = 1; i <= n; i++) p[i] = p[i - 1] + a[i];
mean[0] = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void Print_v(T &a) {
int s = a.size();
for (int i = 0; i < s; i++) cout << a[i] << " ";
cout << endl;
}
void solve() {
long long n, k, sum = 0;
cin >> n >> k;
int arr[n];
vector<pair<int, int>> v;
vector<long long> ans;
for (int i = 1; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
set<long long> s;
long long n;
void dfs(long long x, int y, int z) {
if (x > n) return;
s.insert(x);
if (x * 10 + y != x) dfs(x * 10 + y, y, z);
if (x * 10 + z != x) dfs(x * 10 + z, y, z);
}
int main() {
cin >> n;
for (int i = 0; i < 10; i++) {
for (int j = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const long long LINF = 1e18;
int n, spf[MAX_N];
vector<int> sm_primes, bg_primes;
void sieve() {
for (int i = 0; i <= n; i++) spf[i] = i;
for (int i = 2; i * i <= n; i++)
if (spf[i] == i)
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int col[N];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
void getAC() {
int n;
cin >> n;
int cur = 0;
for (int i = 2; i <= n; ++i) {
if (!col[i]) {
col[i] = ++cur;
for (int j = i + i; j <= n; j += i) {
if (!... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T Sqr(T x) {
T n = x * x;
return n;
}
template <typename T>
T Pow(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * Pow(B, P - 1);
else
return Sqr(Pow(B, P / 2));
}
template <typename T>
T Abs(T a) {
if (a < 0)
return -a;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (2e5) + 1;
const long long MOD = 1e9 + 7;
vector<int> adj[MAXN], nxt[MAXN];
bool used[MAXN];
long long mul(long long x, long long y) {
long long z = x * y;
return (z % MOD);
}
int comp_size(int v) {
int ret = 1;
used[v] = 1;
for (int w : adj[v]) {... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 11000, mm = 110, inf = 1 << 28;
int n, m, l, tt, L;
int bi[mm], a[mm], e[mm], que[mn];
int g[mm][mn], f[mm * mn];
bool c[mn];
int main() {
scanf("%d%d%d", &n, &m, &l);
int i, j, k, s, r, h;
for (i = 1; i <= m; ++i) scanf("%d", &j), c[j] = 1;
for (i = ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long double pi = acos(-1.0);
const string debug_line = "yolo";
const long double PI = acos((long double)-1.0);
const long double eps = 1e-6;
vector<int> Adj[100010];
bool visited[100010];
int counter1 = 0;
int b[100010];
int a[100010];
map<... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const int INF = 0x3f3f3f3f;
int n, k, a[N], b[N];
void init() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
}
int solve(int l, int r) {
memcpy(b, a, sizeof(a));
int ans = 0;
for (int i = l; i <= r; i++) ans += a[i];
... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.