solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> ar;
ar.resize(n);
for (int i = 0; i < n; i++) cin >> ar[i];
int k = 0;
int ind = 0;
while (ind < n) {
if (ar[ind] == ar[0]) {
k++;
ind++;
} else
break;
}
int cl = n / k;
if (n % k ... | 9 |
#include <bits/stdc++.h>
#pragma target("avx")
#pragma target("avx")
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const long long LINF = 1e18;
using namespace std;
long long n, cnt, ans, a, b, c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k, q;
long double doua;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(T& a) {
for (auto x : a) cout << x << " ";
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, i;
cin >> n;
long long a[n + 5];
for (i = 0; i < n; i++) cin >> a[i];
long long cnt = a[0];
l... | 4 |
#include <bits/stdc++.h>
using namespace std;
char a[] = {'^', '>', 'v', '<', '^', '>', 'v', '<', '^', '>', 'v', '<'};
int main() {
char pre, now;
int n, t;
scanf("%c %c", &pre, &now);
scanf("%d", &n);
for (int i = 0; i < 4; ++i)
if (a[i] == pre) t = i;
n %= 4;
t += 4;
if (a[t - n] == now && a[t + n... | 1 |
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M = 1e9+7;
ll mod(ll x){
return (x%M + M)%M;
}
ll mul(ll a, ll b){
return mod((mod(a)*mod(b)));
}
ll add(ll a , ll b){
return mod(mod(a)+mod(b));
}
void solve(){
vector<vector<int>>dp(200001,vector<int>... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long modexpo(long long x, long long p) {
long long res = 1;
x = x % 1000000007;
while (p) {
if (p % 2) res = res * x;
p >>= 1;
x = x * x % 1000000007;
res %= 1000000007;
}
return res;
}
struct compare {
bool operator()(const pair<long long, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string t, p;
cin >> t >> p;
int n = t.size();
int m = p.size();
int a[n];
for (int i = 0; i < n; i++) {
int nb;
cin >> nb;
a[nb - 1] = i;
}
int r(n), x, l(0), j;
while ((r - l) > 1) {
x = (l + r) / 2;
j = 0;
for (int i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> v(n), v1(n);
int count = 0;
for (int i = 0; i < n; i++) {
cin >> v[i];
v1[i] = v[i] % 2;
count += v1[i];
}
if ((count < m) || ((count - m) % ... | 4 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,c,d,e;
char f[5][5][5][5][5];
int main(){
f[1][0][0][1][0] = 'a';
f[1][1][0][2][0] = 'b';
f[2][0][0][1][1] = 'c';
f[2][1][0][1][2] = 'd';
f[1][1][0][1][1] = 'e';
f[2][1][0][2][1] = 'f';
f[2][2][0][2][2] = 'g';
f[1][2][0][2][1] = 'h';
/... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
int l[100010];
int r[100010];
int main() {
while (cin >> n) {
int suml = 0, sumr = 0;
for (int i = 1; i <= n; i++) {
cin >> l[i] >> r[i];
suml += l[i];
sumr += r[i];
}
int result = 0;
int cur = abs(suml - sumr);
for (int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
int count_4 = 0, count_7 = 0;
for (int i = 0; i < a.length(); i++) {
if (a[i] == b[i]) continue;
if (a[i] == '4')
count_4++;
else
count_7++;
}
printf("%d\n", max(count_7, count_4));
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long int mod = 1e9 + 7;
long long ll bsrch(long long ll l, long long ll r, vector<long long ll> &a,
long long ll k) {
if (l >= a.size() || r < 0) return -1;
if (l == r) {
if (a[l] == k)
return l;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>
inline void Cin(T& x) {
char c = getchar();
x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
}
template <typen... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int height = 0;
cin >> n;
int i = 1;
while (n >= (i * (i + 1)) / 2) {
n -= (i * (i + 1)) / 2;
height = i;
i++;
}
cout << height;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
vector<int> v;
string s;
cin >> s;
v.push_back(0);
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'R') v.push_back(i + 1);
}
v.push_back(s.length() + 1);
int maxx = 0;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long solve() {
int n, m, c, c0;
cin >> n >> m >> c >> c0;
vector<pair<int, pair<int, int>>> P;
for (int i = 0; i < n; i++) {
int t, a, b;
cin >> t >> a >> b;
P.emplace_back(t, make_pair(b, a));
}
P.emplace_back(m, make_pair(0, 0));
sort(P.begi... | 19 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:100000000")
using namespace std;
int main() {
int n;
cin >> n;
string s;
int x = 1, y = 1;
for (int(i) = 0; (i) < (n); (i)++) {
cin >> s;
if (s == "UR" || s == "DL")
++x;
else if (s == "UL" || s == "DR")
++y;
else
++x, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<int> > grid(n, vector<int>(m, 0));
vector<vector<int> > track(n + m - 1, vector<int>(2, 0));
for (int i = 0; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s[5010], d[5010], res;
char foo[99];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> s[i] >> foo;
for (int i = 1; i <= n; ++i) d[i] = -1;
d[1] = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
d[j + 1] = max(d[j + 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, l, r, u, d, a, b, c, e, ans;
l = 0;
r = 0;
u = 0;
d = 0;
string s;
cin >> s;
if ((int)s.size() % 2 != 0) {
cout << "-1" << endl;
return 0;
}
for (int i = 0; i < (int)s.size(); i++) {
if (s[i] == 'L') l++;
if (s[i] == '... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int pow_mod(long long int a, long long int b) {
long long int res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
long long int inv_mod(long long int a) { r... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k = 0, a[1000] = {0};
scanf("%lld", &n);
for (int i = 100; i >= 0; i--) {
if (n - i <= 0) continue;
long long p = n - i, sum = n - i;
while (p) {
sum += p % 10;
p /= 10;
}
if (sum == n) a[k++] = n - i;
}
pr... | 4 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
if (x < y) x = y;
}
int main() {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int modulo = 1e9 + 7;
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
int main() {
long long n;
cin >> n;
long long MAX = 10000000000000000;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, k;
cin >> n >> k;
vector<pair<long long, long long>> v1;
for (long long i = 0; i < n; i++) {
long long u, v;
cin >> u >> v;
v1.push_back({u, -1});
v1... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct OO {
OO& operator<(int a) {
printf("%d", a);
return *this;
}
OO& operator<(long long a) {
printf("%lld", a);
return *this;
}
OO& operator<(double a) {
printf("%.15f", a);
return *this;
}
OO& operator<(char a) {
putchar(a);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int x, h, m, rj = 0;
int main() {
cin >> x >> h >> m;
while (h % 10 != 7 && h / 10 != 7 && m % 10 != 7 && m / 10 != 7) {
rj++;
m -= x;
if (m < 0) {
h--;
m += 60;
}
if (h < 0) {
h = 23;
}
}
cout << rj;
return 0;
}
| 1 |
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#inclu... | 19 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 300000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1000000007;
const double PI = acos(-1.0);
template <typename T>
inline T read(T &x) {
x = 0;
int _f = 0;
char ch = getchar();
while (ch < '0'... | 9 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
void solve() {
string s;
cin >> s;
int n = s.size();
int pre[n + 1];
pre[0] = 0;
for (int i = 0; i < n; i++) {
pre[i + 1] = (s[i] == '1');
pre[i + 1] += pre[i];
}
int ans = n;
for (int i = 0; i <= n; i++) {
int cnt1l = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool everyoneIsAwesome(const vector<vector<char>>& world) {
bool everyone = true;
for (auto row : world) {
for (auto cell : row) {
if (cell != 'A') everyone = false;
}
}
return everyone;
}
bool completeEdge(const vector<vector<char>>& world) {
vector... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k, i, mi = 99999999, p, ans = 0;
cin >> n >> k;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < mi) {
mi = a[i];
p = i;
}
}
for (i = 0; i < n; i++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int a[N];
int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
long long x = (long long)a[1] * a[n];
int o... | 8 |
#include <bits/stdc++.h>
using namespace std;
int F[200000];
int main() {
for (int i = 1; i <= 100; i++) {
F[(i * (i + 1)) / 2] = 1;
}
for (int i = 1; i <= 100; i++) {
F[i] += F[i - 1];
}
int N;
scanf("%d", &N);
int ans = 0;
for (int i = 0; i < N; i++) {
int x;
scanf("%d", &x);
ans ^... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b)
cout << a << endl;
else
cout << "1" << endl;
}
| 0 |
#include <bits/stdc++.h>
int n;
int count;
int c[142][10000];
int len[142];
int main() {
scanf("%d", &n);
count = 142;
while ((count * (count - 1)) / 2 > n) --count;
for (register int i = count - 1; i > 0; --i) len[i] = 0;
int d = len[0] = len[1] = n - (count * (count - 1)) / 2;
for (int i = 0; i < d; ++i) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
long long int res = 0;
long long int pos = 0;
for (long long int i = 0; i < n; i++) {
if (a[i] == 0) continue;
if (a[i] > 0)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
FILE* fin = stdin;
int n, i;
fscanf(fin, "%d", &n);
printf("%d\n", n + n / 2);
for (i = 2; i <= n; i += 2) printf("%d ", i);
for (i = 1; i <= n; i += 2) printf("%d ", i);
for (i = 2; i <= n; i += 2) printf("%d ", i);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<long long int> a(n), d(n);
for (int i = (0); i <= (n - 1); i++) cin >> a[i];
sort(a.begin(), a.end());
if (n == 1) {
cout << "-1";
return;
}
set<int> ss;
if (n == 2) {
ss.insert(2 * a[0] - a[1]);
ss.in... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-9;
const long double Pi = 3.1415926535897932384626433832795;
const int N = 100;
const int M = 50;
struct fly {
long long d, s, t, w;
};
bool operator<(const fly& a... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n + n / 2 << '\n';
for (int i = 2; i <= n; i += 2) cout << i << ' ';
for (int i = 1; i <= n; i += 2) cout << i << ' ';
for (int i = 2; i <= n; i += 2) cout << i << ' ';
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c = 1;
cin >> n >> a >> b;
if (n >= 2 && n <= 256 && a >= 1 && b >= 1 && a <= n && b <= n) {
if (((a <= (n / 2)) && (b > (n / 2))) ||
((b <= (n / 2)) && (a > (n / 2)))) {
cout << "Final!";
} else {
while (true) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
set<char> st;
int main() {
int n, ans;
cin >> n;
string str = "";
char chr;
while (n--) {
cin >> chr;
str += chr;
st.insert(chr);
}
int poke = (int)st.size();
int curr_poke = 0;
n = (int)str.size();
int left = 0, right = 0;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, x, g = 1;
for (int i = 0; i < 18; i++) g *= 2;
cin >> n >> x;
if (n == 1) {
cout << "YES" << '\n';
cout << x << '\n';
return 0;
}
if (n == 2) {
if (x == 0) {
cout << "NO"... | 11 |
#include <bits/stdc++.h>
const int N = 300010;
int n, a[N];
int c[N];
int mi[N];
int m;
std::vector<int> vec[N];
class Discretization {
public:
Discretization() { vec_.clear(); }
void Init() { vec_.clear(); }
void Add(int x) { vec_.push_back(x); }
void Build() {
std::sort(vec_.begin(), vec_.end());
vec... | 12 |
#include <bits/stdc++.h>
template <typename T>
inline bool tensionv(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline unsigned int getuint() {
char w = getchar();
while (w < '0' || '9' < w) w = getchar();
unsigned int ans = 0;
for (; '0' <= w && w <= '9'; w = getchar())... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INFint = 1147483547;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-13;
int main() {
ios_base::sync_with_stdio(0);
int a, b;
cin >> a >> b;
string s;
cin >> s;
vector<pair<int, int> > mv(s.si... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 201;
const long long big = 1e18;
const long long block = 800;
const long long mod = 1e6;
long long n;
long long dp[3];
long long sob[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
sob[0] = dp[1] = dp[2] = big;
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool up_max(T& a, const T& b) {
return b > a ? a = b, 1 : 0;
}
template <class T>
bool up_min(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
int n;
int a[100020];
int Z[7][20] = {
{},
{},
{2, 1, 2},
{4, 1, 2, 3, 2},
{6, 1, 2, 3... | 13 |
#include <bits/stdc++.h>
#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif
using namespace std;
const int MOD=998244353, PR=3;
vector<int> X, Y;
int F[300001], Finv[300001];
int mul(int a, int b) {return 1LL*a*b%MOD;}
int fast_pow(int a, int b)
{
in... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int N = 3e5;
vector<int> g[N];
int a[N];
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);
map<pair<long long, long long>, int> dp;
int go(long long a, long long b) {
if (a < b) swap(a, b);
if (dp.find({... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 300000 + 5;
const int INF = 0x3f3f3f3f;
const int P = 1000000007;
const double PI = acos(-1.0);
template <typename T>
inline T read(T &x) {
x = 0;
int _f = 0;
char ch = getchar();
while (ch < '0'... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
long long A, R, M;
cin >> N >> A >> R >> M;
long long C = min(A + R, M);
vector<long long> a(N + 1);
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vec... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2 == 0)
cout << n / 2;
else
cout << -(n + 1) / 2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int MAGIC = 474;
int len;
int a[N];
int cnt, from[N], to[N];
vector<int> where[N];
void init() {
cnt = 1;
from[0] = 1;
to[0] = len;
for (int i = 1; i <= len; i++) {
where[i].clear();
}
for (int i = 1; i <= len; i++) {
where[a[... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2E6 + 1;
const int MOD = 1E9 + 7;
int fact[MAXN];
int invf[MAXN];
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int sub(int a, int b) { return add(a, MOD - b); }
int mul(int a, int b) { return 1ll * a * b % MOD; }
int exp(int a, ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
char b[1009];
string s;
for (int i = 1; i <= 1009; i++) {
cin >> b[i];
if (b[i] == '}') {
break;
} else if (b[i] >= 97 && b[i] <= 122) {
s += b[i];
}
}
sort(s.begin(), s.end());
for (int i = 0; i < s.size()... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> adj(n + 1, vector<int>());
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
map<pair<pair<int, int>, int>, int> mp;
for (int i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int mark[1001];
int main() {
vector<int> v[1001];
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
mark[x]++;
v[x].push_back(i);
}
bool flag = true;
for (int i = 2; i < 1001 && flag; i++) {
if (mark[i])
for (int j = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
int max_index, min_index;
int max = -100000, min = 100000;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] > max) {
max = arr[i];
max_index = i;
}
if (arr[i] <= min) {
min = arr[... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m, x, res, mod = 1e9 + 7;
cin >> n >> m >> x;
long long rem = x % 3;
if (rem == 1)
res = n;
else if (rem == 2)
res = m;
else
res = m - n;
rem = x / 3 + (x % 3 != 0);
if (rem % 2 == 0) res = -res;
res %= mod;
if (re... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
long long powmod(long long a, long long b) {
long long res = 1;
a %= MOD;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % MOD;
a = a * a % MOD;
}
return res;
}
template <typename t1, typename t2>
inline... | 13 |
#include <bits/stdc++.h>
using namespace std;
stack<int> cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
for (int i = 0; i < signed(s.size()); i++) {
if (s[i] == '1')
cnt.push(i);
else if (!cnt.empty())
cnt.pop();
}
while (!cnt.empty()... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, sz = 320;
int n, r, a[N], in[N], out[N], d[N], ind[N];
vector<int> g[N];
vector<pair<int, int> > v, tree[4 * N];
void dfs(int node, int parent = -1, int depth = 0) {
d[node] = depth;
in[node] = v.size();
v.push_back({depth, a[node]});
for (aut... | 15 |
#include <bits/stdc++.h>
using namespace std;
int x, y, n, m, a[100000], k;
vector<long long> v;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
if (v.size() != 0) {
v.push_back(x * y + v[v.size() - 1]);
} else {
v.push_back(x * y);
}
}
for (int i = 1; i <= ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, n, m, k = 0, T, x[30 * 100010], dp[100010],
head[30 * 100010], dis[30 * 100010], vis[30 * 100010],
maxx = -0x3f3f3f3f;
struct node {
long long u, v, Next, val;
} g[30 * 100010];
void add(long long u, lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000, C = 20;
const long long INF = 2e4;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
struct frac {
long long x, y;
frac(long long X = 0, long long Y = 1) {
x = X;
y = Y;
}
frac Norm() {
long long g = gcd(abs(... | 25 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
scanf("%d", &t);
while (t--) {
string s1, s2;
cin >> s1 >> s2;
int len1 = s1.size();
int len2 = s2.size();
if (len2 < len1)
cout << "NO" << endl;
else {
int k = 0, flag = 0, p;
char ch = s1[k];
if (ch !... | 4 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
const long double eps = 1e-7;
struct PT {
long double x, y;
int freq;
PT(long double xx = 0, long double yy = 0) : x(xx), y(yy) {}
PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); }
... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int a[maxn];
int query(int a, int b) {
printf("? %d %d\n", a, b);
int tmp;
cin >> tmp;
return tmp;
}
int main() {
int n;
int abig = query(0, 0);
long long a = 0, b = 0;
for (int i = 29; i >= 0; i--) {
int x = query(a ^ (1 << i), b),... | 12 |
#include <bits/stdc++.h>
using namespace std;
int MBITS = 19;
bool answer_query(vector<int>& a, vector<vector<int> >& dp, int x, int y) {
for (int i = 0; i < MBITS; i++) {
if ((a[x] & (1 << i)) > 0) {
if (x <= dp[i][y]) return true;
}
}
return false;
}
int main() {
int n, q;
cin >> n >> q;
vec... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
const long long mod = 1e9 + 7;
const long long N = 5e5;
const long long INF = 1e9 + 1;
long long n, m, a[N], p;
vector<long long> v;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
... | 5 |
#include <bits/stdc++.h>
inline void in(int &MAGNUS) { scanf("%d", &MAGNUS); }
inline void out(int MAGNUS) { printf("%d\n", MAGNUS); }
inline void in(int &MAGNUS, int &CLAR) { scanf("%d%d", &MAGNUS, &CLAR); }
inline void out(int MAGNUS, int CLAR) { printf("%d %d\n", MAGNUS, CLAR); }
inline void inl(long long &LIV) { sc... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
double m;
cin >> n >> m;
vector<double> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<double> b(n);
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
auto Check = [&](do... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
const int N = 400500;
int n;
long long a[N];
int main() {
cin >> n;
vector<pair<long long, long long> > b;
b.reserve(n);
for (int i =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 200222;
const long long inf = 2000111222000111222LL;
struct line {
int k;
long long b;
line() {}
line(int k, long long b) : k(k), b(b) {}
long long get(int x) const { return 1LL * k * x + b; }
bool operator<(const line &l) const { return k < l.... | 22 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
return ((b == 0) ? a : gcd(b, a % b));
}
vector<int> g[10];
int deg[10];
int ed[10][10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
... | 9 |
#include <bits/stdc++.h>
typedef struct Node* node;
using namespace std;
vector<int> dfs_order;
vector<pair<int, int> > a[100001];
int visited[100001];
map<pair<int, int>, int> m;
int co = 0;
void dfs(int r) {
visited[r] = 1;
for (auto it : a[r]) {
if (!visited[it.first] && it.second == 0) {
co++;
d... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool adj[500][500];
vector<int> llist[500];
int main() {
int n, m;
cin >> n >> m;
int u, v;
for (int i = 0; i < m; i++) {
cin >> u >> v;
adj[u - 1][v - 1] = adj[v - 1][u - 1] = true;
llist[u - 1].push_back(v - 1);
llist[v - 1].push_back(u - 1);
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 14;
int n, x[maxn], y[maxn];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
n = 4 * n + 1;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
for (int j = 0; j < n; j++) {
int mnx = INT_MAX, mny = mnx, mxx = -mnx, mxy = mxx;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 255, M = 16, MOD = 1000000007;
template <typename T>
void read(T &x) {
bool neg = false;
unsigned char c = getchar();
for (; (c ^ 48) > 9; c = getchar())
if (c == '-') neg = true;
for (x = 0; (c ^ 48) < 10; c = getchar()) x = (x << 3) + (x << 1) + ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> adj[100001];
int P[17][100001];
int level[100001];
int sz[100001];
long long down[100001];
long long up[100001];
void dfs(int u, int p) {
P[0][u] = p;
for (int i = 1; i <= 16; i++) P[i][u] = P[i - 1][P[i - 1][u]];
sz[u] = 1;
for (auto& v : adj[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int K = 18;
vector<int> g[N], h[N];
int iter, st[N], en[N], par[K][N], depth[N], token[N];
void dfs(int v, int p, int d = 0) {
depth[v] = d;
par[0][v] = p;
st[v] = iter++;
for (int u : g[v]) {
if (u != p) dfs(u, v, d + 1);
}
en[v]... | 20 |
#include <bits/stdc++.h>
#define Rajpoot ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define loo(i,n) for(i=0;i<n;i++)
#define go(i,sp) for(auto i=sp.begin();i!=sp.end();i++)
#define pb push_back
#define lb lower_bound
#define mo 1000000007
#define pi 3.14159265358979323846264338327... | 0 |
#include <bits/stdc++.h>
int main() {
int i, j, x, n, k;
scanf("%d", &n);
for (x = 2; x * (x + 1) <= n * 2; x++)
;
x--;
printf("%d\n", x + 1);
int d[x + 1][x];
for (i = 0; i < x; i++) printf("%s%d", i ? " " : "", d[0][i] = i + 1);
puts("");
for (j = 1, k = x; j <= x; j++) {
for (i = 0; i < j; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int L = (1 << 20) + 1;
char buf[L], *S, *T, c;
char getchar() {
if (S == T) {
T = (S = buf) + fread(buf, 1, L, stdin);
return (S == T ? EOF : *S++);
}
return *S++;
}
int inp() {
int x = 0, f = 1;
char ch;
for (ch = getchar(); !isdigi... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, a[5][5], x1, y1, numCounts = 0;
for (x = 0; x < 5; x++) {
for (y = 0; y < 5; y++) {
cin >> a[x][y];
if (a[x][y] == 1) {
x1 = x;
y1 = y;
}
}
}
numCounts = abs(2 - x1) + abs(2 - y1);
cout << numCounts;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int mat[100][100];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
int row[100] = {0}, col[100] = {0}, ans = 0;
if (m < n) {
for (int i = 0; i < m; i++) {
int cmin ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
int n;
string s1, s2;
int ctoi(char c) { return c - 'a'; }
int main() {
int t;
cin >> t;
while (t--) {
cin >> n;
cin >> s1;
cin >> s2;
int ok = 1;
set<int> tra[26];
for (int i = 0; i < n; ++i) {
if (s1[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
void print_vars(ostream&... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, dp[1000006];
int main() {
string st;
vector<int> ve;
cin >> st;
for (i = 0; i < st.size(); i++) {
if (st[i] == 'F') ve.push_back(i);
}
if (ve.size() == 0) {
printf("0\n");
return 0;
}
dp[0] = 0;
for (i = 0; i < ve.size(); ... | 12 |
#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int vis[55][55];
int m, n, ans;
int dfs(int x, int y) {
if (vis[x][y] || a[x][y] == '#') return 0;
int ans = 0;
vis[x][y] = 1;
if (a[x][y] == 'G') {
ans++;
}
ans = ans + dfs(x + 1, y);
ans = ans + dfs(x - 1, y);
ans = ans + dfs(x, y + 1);... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) scanf("%d%d", &v[i].first, &v[i].second);
long long ans = v[0].first;
for (int i = 1; i < n; i++)
if (v[i].first > ans)
ans = v[i].first;
else {
int... | 1 |
#include <bits/stdc++.h>
using namespace std;
void OJ() {}
void solve() {
long long a[3];
for (long long i = 0; i < 3; ++i) cin >> a[i];
sort(a, a + 3);
if (a[2] > a[0] + a[1] + 1)
cout << "No";
else
cout << "Yes";
cout << "\n";
}
signed main() {
OJ();
ios::sync_with_stdio(0);
cin.tie(0);
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s[11];
int b[11], c[11];
bool check(string a) {
for (int i = 0; i < 4; i++) {
for (int j = i + 1; j < 4; j++) {
if (a[i] == a[j]) return false;
}
}
return true;
}
int bulls(string a, string b) {
int res = 0;
for (int i = 0; i < 4; i++) {
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxlog = 20;
int a[maxn];
struct Node {
int u, v, c, w;
bool operator<(const Node a) const { return c > a.c || c == a.c && v > a.v; }
} b[maxn << 1];
int fa[maxn][maxlog], mxval[maxn], mxid[maxn], mxw[maxn], st[maxn][maxlog],
ffa[... | 25 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[10001];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n, greater<int>());
for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
putchar(10);
}
return 0;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool seen[1000000];
int m;
long long X[2], M[2];
long long findPos(long long s, long long t, int x, int y) {
memset(seen, 0, sizeof seen);
int q = 0;
do {
seen[s] = true;
s = (x * s + y) % m;
++q;
} while (not seen[s] and s != t);
return s == t ? q : -... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct nd {
int fx, fy, v;
};
struct node {
nd f[2003][2003];
void init() { memset(f, 0, sizeof(f)); }
} vis;
bool mp[2003][2003], fl;
int n, m, s, t;
const int dx[5] = {0, 1, -1, 0, 0};
const int dy[5] = {0, 0, 0, 1, -1};
char c;
void search(int x, int y, int kx, int... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[200004];
bool taken[200004];
string t, p;
int n, m;
bool check(int x) {
for (int i = 0; i < x; i++) {
taken[a[i]] = 1;
}
for (int i = 0, j = 0; i < n; i++) {
if (p[j] == t[i] && !taken[i]) {
j++;
}
if (j == m) {
return true;
}
}... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.