solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long add(long long x, long long y, long long CMOD = MOD) {
return (x + y + CMOD + CMOD) % CMOD;
}
long long mult(long long x, long long y, long long CMOD = MOD) {
return add(x, 0) * add(y, 0) % CMOD;
}
long long fast_expo(long long x,... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244853;
long long cmb[4003][4003];
long long d1[2003][2003], d[2003][2003];
void frm_cmb() {
int i, j;
cmb[1][1] = cmb[1][0] = 1;
for (i = 2; i <= 4000; ++i) cmb[i][0] = 1;
for (i = 2; i <= 4000; ++i)
for (j = 1; j <= i; ++j)
cmb[i][j] =... | 15 |
#include <bits/stdc++.h>
using namespace std;
char IO;
inline long long rd() {
long long res = 0, f = 1;
while (IO = getchar(), IO < 48 || IO > 57)
if (IO == '-') f = 0;
do res = (res << 3) + (res << 1) + (IO ^ 48);
while (IO = getchar(), IO >= 48 && IO <= 57);
if (f) return res;
return -res;
}
const lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[102];
long long b[102];
long long s, t;
bool vis[205];
long long p[205];
long long res[205][205];
const long long INF = 1e14;
bool bfs() {
memset(vis, false, sizeof vis);
memset(p, -1, sizeof p);
queue<long long> q;
q.push(s);
vis[s] = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
cin >> n;
int ans_a, ans_b;
for (int a = 1; a <= n / 2; ++a) {
int b = n - a;
if (a == b) continue;
if (gcd(a, b) == 1) ans_a = a, ans_b = b;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[155];
const unsigned long long B = 1e9 + 9;
unordered_map<unsigned long long, vector<int>> c;
bool trial(int x) {
vector<int> b(n);
for (int i = 0; i < n; i++) {
b[i] = a[i] ^ x;
}
for (int i = 0; i + 1 < n; i++)
if (__builtin_popcountll(b[i]) !... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 1e3 + 10;
const double pi = acos(-1.0);
const int inf = 0x7f7f7ff;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int MAX = 1e6 + 10;
bool visx[MAX];
bool visy[MAX];
int pre[MAX];
int find(int xx) {
if (x... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = acos(-1.0);
const int maxn = 100005;
map<int, int> cc;
int k, b, n;
int a[maxn], tp[maxn];
int MOD(int a, int k) {
a %= k;
return a < 0 ? a + k : a;
}
int main() {
while (cin >> k >> b >> n) {
for (int i = 0; i < n; ++i) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 10;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
reverse(a.begin(), a.end());
reverse(... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
void ReadInput() { cin >> n >> k; }
void Solve() {
long long ans = (k / n) + (k % n != 0LL);
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, j = 0;
cin >> n;
vector<int> arr;
arr.push_back(1);
cin >> x;
for (int i = 1; i < n; i++) {
cin >> y;
if (x == y) {
arr[j]++;
} else {
j++;
arr.push_back(1);
x = y;
}
}
int k1 = 0;
arr.resiz... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int d[300005], mxd;
vector<int> G[300005];
vector<pair<int, int> > Ans;
void DFS(int u, int p, int t) {
int ot = t;
Ans.push_back({u, t});
for (int v : G[u])
if (v != p) {
if (t == mxd) t = mxd - d[u], Ans.push_back({u, t});
++t;
DFS(v, u,... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-'; t = getchar())
;
if (t == '-') neg = true, t = getchar();
for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
if ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 100;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
ret... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n;
int niz[maxn];
bool pobeda[maxn];
vector<int> g[maxn];
bool visited[maxn];
void dfs(int v) {
visited[v] = 1;
for (auto u : g[v]) {
if (!visited[u]) dfs(u);
if (!pobeda[u]) pobeda[v] = 1;
}
}
int main() {
cin >> n;
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long A[100011];
long long pre[100011];
long long memo[100011];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
memset(memo, -1, sizeof memo);
cin >> n;
for (long long i = 0; i < n; i++) cin >> A[i];
sort(A, A + n);... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int p[107];
double res;
double curr[107][107];
double last[107][107];
int przejscia[4][107][107][2 * 107];
vector<pair<int, int> > v[4][107][107];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> k;
k = min(k, 1000);
for (int i =... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
void findNDigitNumsUtil(int n, int sum, char* out, int index) {
if (index > n || sum < 0) return;
if (index == n) {
if (sum == 0) {
out[index] = '\0';
v.push_back(out);
}
return;
}
for (int i = 0; i <= 9; i++) {
out[inde... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct cntSet {
public:
void erase(int);
void insert(int);
int getLower(int);
int getHigher(int);
private:
int fen[N];
int getSum(int);
void add(int, int);
};
int n, a[N], db[N], dbs;
cntSet _right, _left;
int main() {
ios::sync_wi... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long n;
cin >> n;
vector<long long> A(n);
for (long long i = 0; i < n; i++) {
cin >> A[i];
}
sort(A.begin(), A.end());
long long k = 0;
for (long long i = 0; i < n; i++) {
if (A[i] > k) {
k++;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
string s, a, b;
int n;
int main() {
cin >> n;
m["void"];
m["errtype"] = -1;
while (n--) {
cin >> s;
if (s == "typedef") {
string t = "";
int cur = 0;
cin >> a >> b;
for (int i = 0; i < a.size(); i++) {
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
int x[3] = {2, 3, 5};
int gcd(int a, int b) {
if (b == 0) return a;
gcd(b, a % b);
}
int main() {
int n, m;
while (~scanf("%d%d", &n, &m)) {
if (n == m) {
printf("0\n");
continue;
}
int ans = 0;
bool temp = 0;
int u = gcd(n, m);
n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int arr[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, arr + n);
int ans = 2e9 + 5;
int cnt = 0;
for (int i = 0; i < n - 1; i++) {
if (abs(arr[i] - arr[i + 1]) < ans) {
cnt = 1;
ans = a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s;
if (s[0] == 'f')
s.insert(3, "://");
else
s.insert(4, "://");
int ind = s.find("ru");
if (s[ind - 1] == '/') {
s.replace(ind, 2, "ab");
int y = s.find("ru");
s.insert(y, ".");
int x = s.find("ru");
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a > b)
cout << "First";
else
cout << "Second";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, mw, mb, ans;
int a[30];
int main() {
scanf("%d%d%d", &n, &mw, &mb);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n / 2; i++) {
if (a[i] == a[n - i + 1] && a[i] != 2)
continue;
else if (a[i] == a[n - i + 1] && a[i] == 2)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1, ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
return x * f;
}
int T, n, a[200005], ans[200005], col[200005];
char s[200... | 10 |
#include <bits/stdc++.h>
using namespace std;
int pl[501][501] = {false};
int main() {
size_t x, y, x0, y0, a = 0;
string s;
cin >> x >> y >> x0 >> y0;
cin >> s;
for (size_t i = 0; i < s.size(); i++) {
if (pl[x0][y0] == false) {
pl[x0][y0] = true;
cout << 1 << " ";
a++;
} else
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, s, o, l;
string x;
cin >> o >> l >> x;
if (l > o / 2) {
for (i = l; i < o; i++) cout << "RIGHT" << endl;
for (i = o - 1; i >= 0; i--) {
cout << "PRINT " << x[i] << endl;
if (i != 0)
cout << "LEFT" << endl;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char c[maxn];
int a[maxn];
bool vis[maxn];
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (register int i = 1; i <= n; ++i) {
cin >> c[i];
}
for (register int i = 1; i <= n; ++i) {
cin >> a[i];
}
int i = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a;
swap(a, m);
u -= t * v;
swap(u, v);
}
assert(m == 1);
return u;
}
template <typename T>
class Modular {
public:
using Type = typename decay... | 24 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[300005];
bool visit[300005];
bool cyc[300005];
long long int dp[300005][26], fl = 0;
string s;
void dfs(long long int x) {
visit[x] = true;
cyc[x] = true;
for (auto it : adj[x]) {
if (cyc[it]) fl = 1;
if (!visit[it]) dfs(it);
}
fo... | 9 |
#include <bits/stdc++.h>
int n, m;
char map[550][550], vis[550][550];
int xx[1000100], yy[1000100], top = 0;
char cc[1000100];
int dfs(int x, int y) {
vis[x][y] = 1;
xx[top] = x, yy[top] = y, cc[top] = 'B';
top++;
if (map[x + 1][y] == '.' && !vis[x + 1][y]) dfs(x + 1, y);
if (map[x][y + 1] == '.' && !vis[x][y... | 11 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
string s[1001];
unsigned long long d[1001][1001][4];
int n, m;
bool check(int x, int y, int dir, int v) {
int nx = x + dx[dir];
int ny = y + dy[dir];
if (!(nx >= 0 && nx < n && ny >= 0 && ny < m)) return false;
if (s[n... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const int MOD = 1e9 + 7;
vector<int> mm[2];
int sum[maxn];
int main() {
int n, k;
while (scanf("%d%d", &n, &k) != EOF) {
getchar();
mm[1].clear();
mm[0].clear();
sum[0] = 0;
for (int i = 1; i <= n; i++) {
char a;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> val[32000];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int a, b, p, q;
scanf("%d%d%d%d", &a, &b, &p, &q);
int n = (int)sqrt(b - a + 1), m = 1;
for (int i = 0; i < n; i++) {
val[i + 1].first = 2LL * (a + i) * p % (q * 2);
... | 19 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p;
int main() {
string s[8];
int res = 0;
for (int i = 0; i < 8; i++) {
cin >> s[i];
if (s[i] == "BBBBBBBB")
res++;
else
p.push_back(i);
}
if (res == 8)
cout << res << endl;
else {
for (int i = 0; i < 8; i++) {
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxs = 500000, key = 1000003;
char dat[maxs + 1];
int calcleft(int n, int m) {
int i, j, p;
int now, temp;
int ans = 1;
for (i = 0; i < n; i++) {
now = 2;
for (p = i * m, j = 0; j < m; j++, p++)
if (dat[p] == '1' || dat[p] == '2') {
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MD = 3;
const int MAX_POW = 1000010;
mt19937 mt(time(0));
int md[MD], p[MD];
int pows[MD][MAX_POW + 10];
void modAdd(int &a, int b, int md) {
a += b;
if (a >= md) a -= md;
}
void modSub(int &a, int b, int md) {
a -= b;
if (a < 0) a += md;
}
void modMul(int... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010;
char mp[MAXN][MAXN];
int col[MAXN], diag[MAXN];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; ++i) scanf("%s", mp[i]);
memset(col, 0, sizeof(col));
memset(diag, 0, sizeof(diag));
int ans(0);
for (i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], k;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
int ans = 1e9;
map<char, int> mp;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
mp[c]++;
}
for (int i = 0; i < k; i++) {
ans = min(ans, mp[... | 0 |
#include <bits/stdc++.h>
using namespace std;
string board[30];
vector<string> v;
string func(int x1, int y1, int x2, int y2) {
int x = x2 - x1, y = y2 - y1;
string ans, t;
t = "";
for (int i = 0; i < x; i++) {
for (int j = 0; j < y; j++) t += board[x1 + i][y1 + j];
}
ans = t;
t = "";
for (int i = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[100001];
map<string, int> m;
map<int, string> M;
string s;
int cnt[6], n;
bool is[100001];
int color[100001];
void func(int K) {
int i;
for (i = 1; i <= n; i++) {
if (!is[i]) {
if (v[i][0] == K or v[i][1] == K) {
if (cnt[K] > 0) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int graph[405][405];
queue<int> qi;
int dis[405];
int main() {
int n, m, a, b;
scanf("%d", &n);
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", &a);
scanf("%d", &b);
graph[a][b] = 1;
graph[b][a] = 1;
}
if (graph[1][n]) {
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, c, a[200000], b[200000], s, p, ans;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> c;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
for (int x = 1; x <= 20000; x++) {
s = 0;
for (int i = 1; i <= n; i++) {
p = a[i] * x;
s ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
const int N = 55;
int mask[27][27];
int S[N][N], T[N][N], n, m;
char s[N],... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const int SIZE = 2e5 + 5;
const long long INF = 1LL << 60;
const double eps = 1e-4;
const double PI = 3.1415926535897932;
int main() {
int n;
cin >> n;
int bb = 0, bv = 0;
for (int i = (1); i < (n); ++i) {
int cur = 0;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n), b(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
scanf("%d", &b[i]);
}
map<int, pair<int, int> > mp;
mp[0] = pair<int, int>(-1, -1);
long long sa(0), sb... | 22 |
#include <bits/stdc++.h>
using namespace std;
inline int max(int x, int y) { return x > y ? x : y; }
inline int min(int x, int y) { return x < y ? x : y; }
const int N = 1000 + 50;
const int mod = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> prime_mods = {
1000000000108174411LL, 1000000000108174427LL, 1000000000108174433LL,
1000010000005470301LL, 1000010000005470329LL, 1000010000005470341LL,
};
long long gcd(long long a, long long b) {
while (b != 0) {
a = a % b;
swap(a, b);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e6;
int ans, m, n, t1, t2, t3;
int main() {
ans = 1 << 30;
scanf("%d %d %d", &t1, &t2, &t3);
ans = min(ans, 2 * (t1 + t2));
ans = min(ans, t2 + t3 + t1);
ans = min(ans, 2 * (t1 + t3));
ans = min(ans, 2 * (t2 + t3));
printf("%d\n", ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, const T &b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, const T &b) {
if (b > a) a = b;
}
struct edge {
int to, cap;
long double cost;
int rev;
};
const int inf = 1e9 + 10;
const int maxn = 1e3 ... | 16 |
#include <bits/stdc++.h>
void polyline(int a, int b, int &x, int &y) {
int dx[2] = {1, 0}, dy[2] = {0, 1};
x = y = 0;
while (a > 0) {
if (b < (1 << (2 * (a - 1)))) {
int x0 = dx[1], x1 = dx[0];
dx[0] = x0;
dx[1] = x1;
x0 = dy[1];
x1 = dy[0];
dy[0] = x0;
dy[1] = x1;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
int n, ad = 0, ans = 0;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) {
if (i == 0) {
ans = 1;
continue;
}
if (s[i] != s[i - 1])
ans++;
else
ad++;
}
ad = min(ad, 2);
cout << a... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
return lc == '-' ? -s : s;
}
void write(long long x) {
if (x < 0) put... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline void Swap(long long &x, long long &y) {
long long Temp = x;
x = y;
y = Temp;
}
inline long long Min(long long x, long long y) { return x < y ? x : y; }
inline long long Max(long long x, long long y) { return x > y ? x : y; }
inline void read(long long &x) {
x... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cases;
cin >> cases;
for (int t = 0; t < cases; t++) {
int r, c, x, y;
cin >> r >> c >> x >> y;
int area1, area2, area3, area4;
area1 = r * (c - y - 1);
area2 = r * (y);
area3 = c * (r - x - 1);
area4 = c * (x);
int m =... | 0 |
#include <bits/stdc++.h>
inline int read() {
register int t = 0;
register char v = getchar();
while (v < '0') v = getchar();
while (v >= '0') t = (t << 3) + (t << 1) + v - 48, v = getchar();
return t;
}
using namespace std;
int n, m, a[1000002], k, dp[100002][6], ans, t;
int main() {
t = read();
while (t-... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, a, b;
map<int, int> num;
int bel[maxn], ax[maxn], bx[maxn], seq[maxn];
void bad() {
printf("NO\n");
exit(0);
}
void dfs(int x) {
if (bel[ax[x]] != -1 && bel[bx[x]] != -1) bad();
if (bel[ax[x]] == -1) {
bel[x] = bel[ax[x]] = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long mod = 1e9 + 7;
char a[51][1001];
long long dp[1001][1001], num[1001];
int main() {
long long x, ans = 1;
scanf("%d%d", &m, &n);
for (int i = 0; i < n; i++) scanf("%s", &a[i]);
map<long long, long long> mp;
dp[0][0] = 1;
for (int i = 1; i <= 1... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double E = 1e-8;
bool check(vector<double>& dists, double eps, double r, int K) {
double p = 1;
r = r * r;
vector<vector<double> > tbl(dists.size() + 1,
vector<double>(dists.size() + 1));
tbl[0][0] = 1;
for (int i = 1; i < tbl.s... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
char ch;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return f * x;
}
int n;
int a[200002], ud[20... | 16 |
#include <bits/stdc++.h>
struct sportsmen {
int l;
int r;
int time;
int profit;
};
struct tp {
int time;
int profit;
};
int main(void) {
tp* opt;
sportsmen data[100];
int n;
int m;
int i;
int j;
int sum;
char c;
scanf("%d %d", &n, &m);
opt = new tp[n];
for (i = 0; i < n; i++) {
opt... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1001];
int main() {
char s[110];
int c, c1, l = 0;
for (int i = 0; (c = getchar()) > 31; ++i) {
c1 = 0;
for (int j = 0; j < 8; ++j) {
c1 = c1 * 2 + c % 2;
c /= 2;
}
cout << ((256 + l - c1) % 256) << endl;
l = c1;
}
return 0;
}... | 5 |
#include <bits/stdc++.h>
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cout.write(names, comma -... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
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();
}
return x * f;
}
inline void write(int x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int l, cnt, sum, ans;
char s[5010];
int main() {
scanf("%s", s);
l = strlen(s);
for (int i = 0; i < l; i++) {
cnt = sum = 0;
for (int j = i; j < l; j++) {
if (s[j] == '(')
sum++;
else if (s[j] == ')')
sum--;
else {
cnt... | 10 |
#include <bits/stdc++.h>
int main() {
int n, bowls, plates, dish, j, flag = 0, count = 0;
scanf("%d%d%d", &n, &bowls, &plates);
for (int i = 1; i <= n; i++) {
scanf("%d", &dish);
if (dish == 1) {
if (bowls >= 1)
bowls--;
else {
count++;
}
} else if (dish == 2) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long arr[160000];
long long arr1[160000];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
long long a, b;
for (int i = 0; i < n; i++) {
... | 8 |
#include <bits/stdc++.h>
int main() {
int n, k, i, j = -1;
int pre[1000004];
char s[1000004];
scanf("%d%d\n", &n, &k);
s[0] = getchar();
pre[0] = -1;
for (i = 1; i < n; ++i) {
s[i] = getchar();
while (j != -1 && s[j + 1] != s[i]) j = pre[j];
if (s[j + 1] == s[i]) ++j;
pre[i] = j;
}
for... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double pi =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
int t[25] = {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};
char s[10];
int main() {
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxN(1e5 + 10), maxM(maxN);
typedef int i_N[maxN];
int N, M;
namespace graph {
i_N deg, P, Fx;
pair<int, int> edge[maxM];
vector<pair<int, int> > adj[maxN];
vector<int> topo;
void link(const int u, const pair<int, int> &E) { adj[u].push_back(E); }
void dfs(const i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010];
char u;
void scan(int &x) {
int f = 1;
while (u = getchar(), u < '0' || u > '9') {
if (u == '-') f = -1;
};
x = u - '0';
while (u = getchar(), u >= '0' && u <= '9') x = x * 10 + u - '0';
x *= f;
}
int main() {
int t;
scan(t);
whi... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, t;
while (~scanf("%d%d%d%d%d", &n, &a, &b, &c, &t)) {
int res = 0, x;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
res = res + a + (c - b) * (t - x);
}
printf("%d\n", max(a * n, res));
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)10e9;
const long long INF = (long long)10e18;
const double PI = 2 * acos(0.0);
int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, +1, -1};
int hx[] = {+1, -1, -1, +1, -2, -2, +2, +2};
int hy[] = {+2, +2, -2, -2, +1, -1, +1, -1};
int f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, p, l, r, first, N, E, x, y;
int a[100001], b[100001];
vector<int> v[2000];
map<int, bool> M;
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
v[1].push_back(a[1]);
first = 0;
for (i = 1; i <= n; i++) {
x = first;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
int mas[110];
for (int i = 0; i < N; i++) {
scanf("%d", &mas[i]);
}
int sol = 0;
for (int i = 0; i < N; i++) {
if (mas[i] > sol) sol = mas[i];
}
for (int k = 0; k < N; k++) {
int xor_s = mas[k];
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a, c[10000], l, mn, p;
bool us[10000];
int main() {
cin >> a;
for (int i = 0; i < a; i++) {
cin >> c[i];
}
sort(c, c + a);
while (a - l) {
p++;
int k = 0;
for (int i = 0; i < a; i++) {
if (!us[i] && k <= c[i]) {
k++;
l++;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int r, x1, y1, x2, y2;
cin >> r >> x1 >> y1 >> x2 >> y2;
double d = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
cout << (long long int)ceil(d / (2 * r));
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmax(T &_a, T _b) {
if (_b > _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
bool setmin(T &_a, T _b) {
if (_b < _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
T gcd(T _a, T _b) {
ret... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long ti[1001], pr[1001];
long long n, cur = 0;
long long ans;
long long ansA, ansB, ansC;
long long num = 1, minA, minB;
void dfs2(long long x, long long tmp) {
if (tmp > minB) return;
if (x == n + 1) {
long long A = cur, B = tmp, C ... | 21 |
#include <bits/stdc++.h>
using namespace std;
char str[200010];
char str2[200010];
int main() {
int n, m;
vector<int> V[1500];
scanf("%d %d", &n, &m);
scanf("%s", str);
for (int i = 0; i < m; i++) {
V[str[i] - 'a'].push_back(i);
}
int in;
for (int j = 0; j < n; j++) {
scanf("%s", str2);
long... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return a > b; }
int a[100010], b[100010];
int main() {
int n, m, u, v, i;
scanf("%d%d%d%d", &n, &m, &u, &v);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= m; i++) scanf("%d", &b[i]);
sort(a + 1, a + n + 1);
sort(b + 1, b... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
int i, j, k;
vector<long long int> v;
for (i = 0; i < n; i++) {
long long int x;
cin >> x;
v.push_back(x);
}
long long int lo = n + 1, hi = 1000000000000000000, mid;
i = n - 1;
while (i >= 0) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, e, f;
char t1 = 'A', t2 = 'B', t3 = 'C';
void output1(int a, int b, int c, int n) {
printf("%d\n", n);
int i, j;
char aa[104], bb[104], cc[104];
for (i = 0; i < n; ++i) {
aa[i] = 'A';
bb[i] = 'B';
cc[i] = 'C';
}
aa[n] = bb[n] = cc[n] ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a;
int main() {
cin >> a;
cout << 6 * a * (a - 1) + 1 << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> qs;
void recur(vector<long long>::iterator from, vector<long long>::iterator to) {
const long long n = to - from;
if (n == 1) {
return;
}
const long long half = n / 2;
const auto mid = from + half;
recur(from, mid);
recur... | 15 |
#include <bits/stdc++.h>
using namespace std;
int ar[20010];
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &ar[i]);
int k, sm = 0, mx = -999999999;
int j = 0;
for (i = 1; i <= n / 2; i++) {
if (n % i != 0 || n / i < 3) continue;
for (j = 0; j < i; j++) {
sm = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, arr[2002], same, cnt, found, temp;
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; ++i) cin >> arr[i];
while (count(arr, arr + n, 1) != n) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, d, z;
pair<int, int> p[1024];
int main() {
int i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a >> b >> c >> d;
p[i].first = -a - b - c - d;
p[i].second = i;
}
sort(p + 1, p + n + 1);
for (i = 1; i <= n; i++) {
if (p[i].second == ... | 0 |
#include <iostream>
using namespace std;
int t, n, k;
int main() {
cin >> t;
while (t--) {
cin >> n >> k;
cout << n - k + k / 2 << endl;
for (int i = n; i > k; --i) {
cout << i << " ";
}
for (int i = k - 1; i > (k - 1) / 2; --i) {
cout << i << " ";
}
cout << endl;
}
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 1e18;
const long long int N = 1e5 + 5;
void HyperBeast() {
long long int n, m, k;
cin >> n >> m >> k;
vector<pair<long long int, long long int> > v(k);
for (auto &i : v) {
cin >> i.first >> i.second... | 10 |
#include <bits/stdc++.h>
struct line {
line(int dx_, int dy_, int X_, int Y_)
: dx(dx_), dy(dy_), X(X_), Y(Y_), ind(cnt++) {
if (dx < 0) {
dx *= -1;
dy *= -1;
}
}
static int cnt;
int dx, dy, X, Y, ind;
};
int line::cnt = 0;
bool operator==(const line& a, const line& b) {
if (!a.dx) r... | 11 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
long double eps = 1e-9;
int n;
int mod = 1e9 + 7;
void solve()
{
cin>>n;
vector<int>A(n);
vector<int>B(n);
int sum1=0;
for(int i=0;i<n;i++)
{
cin>>A[i];
sum1+=A[i];
}
int sum2=0;
for(int i=0;i<n;i++)
{
cin>>B[i];
sum2+=B[i];
}
if(sum... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const long long mod = 998244353, G = 3;
inline long long power(long long, long long);
inline void ntt(int, long long*, bool);
int t[maxn << 2];
long long fac[2][maxn];
long long f[maxn << 2], g[maxn << 2];
long long ans[maxn];
int main() {
int n;
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int f[] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1};
int main() {
std::ios::sync_with_stdio(0);
int k;
cin >> k;
long long res = 0;
while (res < (long long)1e18 && k) {
if (k >= 2) {
k -= 2;
res = res * 10 + 8;
} else {
k--;
res = res * 10 + 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[n], sum = 0;
for (long long int i = 0; i < (n); i++) {
cin >> a[i];
sum += a[i];
}
long long int flag = 0;
for (long long int i = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int n, d;
map<string, int> id;
int m;
string fromid[2000];
int getid(string &s) {
if (((id).find(s) != (id).end())) {
return id[s];
} else {
fromid[m] = s;
return id[s] = m++;
}
}
struct CMD {
int a, b, t;
} C[2000];
int lst[2000][2000];
boo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int> > edges;
vector<pair<int, int> > ans;
int maxdeg = 0;
void dfs(int idx, int& t, int backt = -1, int fa = -1) {
ans.push_back(make_pair(idx, t));
int cnt = edges[idx].size() - (fa == -1 ? 0 : 1);
for (int to : edges[idx]) {
if (to == fa) c... | 18 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.