solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
sort(s.begin(), s.end());
int cnt = s.end() - lower_bound(s.begin(), s.end(), s.back());
while (cnt--) cout << s.back();
cout << '\n';
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, k, p;
string c;
int main() {
cin >> c;
n = c.size();
while (c[i] == '0') m++;
p = 0;
for (i = m; i < n - 1; i++) {
if (c[i] != '0')
cout << c[i];
else if (p == 1)
cout << c[i];
else
p = 1;
}
if (p == 1) cout << c[n - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n + 1];
for (int i = 1; i <= n; i++) a[i] = 1;
string s;
cin >> s;
char ch[n];
for (int i = 1; i < n; i++) ch[i] = s[i - 1];
for (int i = 1; i < n; i++... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
cerr << str << " : " << t << "\n";
}
template <class T, class... S>
void dbs(string str, T t, S... s) {
int idx = str.find(',');
cerr << str.substr(0, idx) << " : " << t << ",";
dbs(str.substr(idx + 1), s...);
}
templat... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, x1, y1, x2, y2;
while (cin >> a >> b >> x1 >> y1 >> x2 >> y2) {
tie(x1, y1) = make_pair(x1 + y1, y1 - x1);
tie(x2, y2) = make_pair(x2 + y2, y2 - x2);
a *= 2;
b *= 2;
x1 = x1 / a + (x1 > 0);
y1 = y1 / b + (y1 > 0);
x2 = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
#pragma GCC diagnostic ignored "-Wsign-compare"
vector<long long> b;
vector<long long> w;
vector<vector<long long> > adj;
long long n, m;
vector<vector<pair<long long, long long> > > dp;
pair<long long, long long> mx(pair<long long, long long> ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
char str[MAXN];
inline int getTime(int h, int m, char ch) {
if (h == 12) h = 0;
int tmp = (ch == 'a') ? 0 : 12;
return (h + tmp) * 60 + m;
}
int main() {
int n, h, m, ch;
while (cin >> n) {
getchar();
int days = 0;
int pre = -1, c... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
int c = 0;
int z = i;
while (z + 1 < s.size() && s[z] == s[z + 1]) {
z++;
}
c = z - i;
c++;
if (c % 2) {
for (int j = 0; j < c; ... | 6 |
#include <bits/stdc++.h>
const unsigned int M = 1000000007;
using namespace std;
bool check_prime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return true;
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, a, b, t = 1, f = 0, j = 0;
std::vector<int> v;
w... | 7 |
#include <bits/stdc++.h>
using namespace std;
int val[200005];
int nxt[200005];
vector<pair<int, int> > vec;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, big = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> val[i];
nxt[i] = (i + 1);
big = max(big, val[i]);
vec.push_... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[2000];
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
long long ans = 0;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
ans += min(a[x - 1], a[y - 1]);
}
cout << ans;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1;
const long long inf = 1e18 + 7;
long long t, n, a[maxn], i, j;
long long getnum(long long m) {
long long cnt = 0;
for (i = n; i > 0; i--)
if (a[i] > m) cnt++;
return cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[5][2000];
int pos[5][2000];
int dp[2000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 0; i <= k - 1; ++i)
for (int j = 0; j <= n - 1; ++j)
cin >> a[i][j], a[i][j]--, pos[i][a[i][j]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int N, P;
signed long long dp[51][51][51][51];
signed long long p2[51];
const int CN = 101;
signed long long C[CN][CN];
signed long long CS[CN][2];
signed long long mo = 1000000007;
int col[51];
void solve() {
int i, j, k, l, r, x, y;
string s;
for (i = 0; i < (CN); i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int sum[101][30030];
char g[101][30030];
int main() {
int i, j, ok = true;
cin >> n >> m;
for (i = 0; i < n; i++) {
bool f = false;
scanf("%s", g[i]);
for (j = 0; j < 3 * m; j++) {
if (j == 0)
sum[i][j + 1] = (g[i][j] == '1');
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int mequal[53][53], in[53] = {0};
int visit[53][53][53][53], dp[53][53][53][53] = {{{{0}}}};
char card[53][3];
int mequall(int a, int b) {
return card[a][0] == card[b][0] || card[a][1] == card[b][1];
}
int check(int n, int a, int b, int c) {
if (n == 1)
return 2;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long double n, p, a[100001], b[100001], sum;
bool Ver(long double time) {
long double x = 0;
for (int i = 1; i <= n; i++) {
x += max((long double)0, time * a[i] - b[i]);
}
return p * time >= x;
}
int main() {
cin >> n >> p;
for (int i = 1; i <= n; i++) cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int l;
int r;
int len;
};
bool operator<(node a, node b) {
if (b.len > a.len)
return true;
else if (b.len < a.len)
return false;
else {
return b.l < a.l;
}
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
map<string, int> pol;
map<string, int> en;
cin >> n >> m;
int whole = 0;
string j;
for (int i = (0); i < (n); i++) {
cin >> j;
pol[j] = 1;
}
for (int i = (0); i < (m); i++) {
cin >> j;
en[j] = 1;
if (pol[j] == 1) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class R>
inline void Readin(R &K) {
bool F = K = 0;
char C = getchar();
while (C < '0' || C > '9') {
if (C == '-') F = 1;
C = getchar();
}
while (C <= '9' && C >= '0') K = (K << 1) + (K << 3) + C - '0', C = getchar();
if (F) K = -K;
}
template ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mxsz = 2e5 + 5;
vector<long long> X[mxsz], Y[mxsz];
struct DSU {
vector<long long> p;
inline long long find(long long n) {
return p[n] == n ? n : p[n] = find(p[n]);
}
inline void join(long long a, long long b) { p[find(a)] = find(b); }
DSU(long... | 11 |
#include <bits/stdc++.h>
using namespace std;
int getInp() {
int t;
cin >> t;
if (t == 0 || t == -1) {
exit(0);
}
return t;
}
template <typename T>
int test(const T &inp) {
cout << inp << endl;
return getInp();
}
int main() {
int n;
n = test('a') + 1;
int na = test(string(n - 1, 'b'));
int nb ... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
return (a / gcd(a, b)) * b;
}
int main() {
string s;
while (cin >> s) {
int len = s.size();
int up = 0;
for (int i = 0; i < len; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[100010], j;
int main() {
cin >> n >> k;
for (long long i = 1; i <= n; i += 1) cin >> a[i];
bool ok = 1;
for (long long i = n - 1; i >= 1; i -= 1)
if (a[i] != a[i + 1]) {
j = i;
ok = 0;
break;
}
if (ok) {
cout << 0;
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mmp[110][110], ans = 100000, now = 0, sum[110][110];
int dfs(int x, int y, int k) {
if (x + k - 1 > n || y + k - 1 > m) return 10100000;
int cnt = 0, cur = sum[x + k - 1][y + k - 1] - sum[x - 1][y + k - 1] -
sum[x + k - 1][y - 1] + sum[x -... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 100000007;
const int maxe = 1e6 + 85;
long long n, m, x, ans;
string s;
int a[15]{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int cnt[4]{4, 9, 25, 49};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (int i = 0; i < 15... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long p;
long long t[maxn];
int od[maxn];
vector<long long> lsh;
vector<int> id[maxn];
queue<int> que;
priority_queue<long long, vector<long long>, greater<long long> > pq1;
priority_queue<int, vector<int>, greater<int> > pq2;
deque<pair<int, ... | 15 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SZ = 1 << 13;
char buff[SZ], *pos = buff + SZ - 1;
char gc() {
if (++pos == buff + SZ) fread(pos = buff, 1, SZ, stdin);
return *pos;
}
} // namespace io
template <typename T>
inline void read(T &x) {
x = 0;
int f = 1, c = io ::gc();
for (... | 15 |
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
using namespace std;
const int maxn = 1e5+5;
int a[maxn],b[maxn];
int main(){
int T;
cin >> T;
while(T--){
int n;
cin >> n;
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[101];
int level, t, x;
int main() {
cin >> t;
cin >> level;
for (int i = 1; i <= level; ++i) {
cin >> x;
a[x]++;
}
cin >> level;
for (int i = 1; i <= level; ++i) {
cin >> x;
a[x]++;
}
bool check = true;
for (int i = 1; i <= t; ++i)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 5e4 + 1, th = 16, t8 = 1 << 8;
int n, q, a[mx];
int child[mx * th][2];
int vans[mx * th];
vector<int> e[mx];
int par[mx], part8[mx];
bool mark[mx];
int h[mx];
int vs[mx][t8];
int pt;
bool bith;
int get(long long int val, long long int v = 0,
long long... | 24 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int main() {
int T;
string s;
scanf("%d", &T);
while (T--) {
cin >> s;
int l = s.size();
ans.clear();
for (int i = 0; i < l - 2; ++i) {
if (i < s.size() - 4 && s[i] == 't' && s[i + 1] == 'w' &&
s[i + 2] == 'o' && s[i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int N = 1e9 + 7;
int n, m;
char mat[504][504];
int vis[504][504];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
void solve() {
cin >> n >> m;
memset(vis, 0, sizeof(vis));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> ma... | 12 |
#include <bits/stdc++.h>
#define jh(x, y) (x ^= y ^= x ^= y)
#define loc(x, y) ((x - 1) * m + y)
#define lowbit(x) (x & -x)
typedef long long ll;
const int N = 1e6 + 5, INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double PI = acos(-1);
using namespace std;
namespace fast_IO {
ll read() {
ll x = 0;
char c;
bool flag = ... | 14 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll N = 400001, L = 19;
vector<ll> g[N];
vector<pair<ll, ll>> ng[N];
ll tin[N], tout[N], ct, ord[N], fv[N], s[N], qq[N], h[N], up[L][N], vir[N],
ft[N], k;
set<vector<ll>> qs;
void dfs(ll v, ll p) {
ord[ct] = v;
tin[... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
long long data[N * 2], sum[N * 2];
int last[N * 2], f[N * 2];
struct AC_IO {
long long read() {
char c = getchar();
while (!isdigit(c)) c = getchar();
long long x = 0ll;
while (isdigit(c)) {
x = x * 10ll + c - '0';
c... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int LIM = 100001;
bool prime[LIM];
void sieve(int n) {
prime[1] = false;
for (int i = 2; i <= n; ++i) {
prime[i] = true;
}
for (int i = 2; i * i <= n; ++i) {
if (prime[i]) {
for (int j = i * i; j <= n; j += i) {
prime[j] = false;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
bool i1, i2, i3, i4, d1, d2, d3, d4, t1, t2, o1;
cin >> i1 >> i2 >> i3 >> i4;
d1 = i1 ^ i2;
d2 = (i3 || i4);
d3 = i2 && i3;
d4 = i1 ^ i4;
t1 = d1 && d2;
t2 = (d3 || d4);
o1 = t1 ^... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long N = 101;
long long mul(long long a, long long b) { return (a * b) % MOD; }
long long add(long long a, long long b) { return (a + b) % MOD; }
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
{
int y, b, r;
cin >> y >> b >> r;
if (r > b) {
if (b > y)
cout << (3 * y) + 3;
else
cout << 3 * b;
} else {
if (y < (r - 2))
cout << (3 * y) + 3;
else
cout << (3 * r - 3);
}
}
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string arr[n];
for (int i = 0; i < n; ++i) {
arr[i] = string(m, '0');
for (int j = 0; j < m; cin >> arr[i][j], ++j)
;
}
int r = 2 * n;
while (!((r / 2) % 2)) {
r /= 2;
for (int i = 0; i < n; i += r) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 51;
const int WMAX = 1000;
int N;
int a[2 * NMAX];
int main() {
scanf("%d", &N);
for (int i = 1; i <= 2 * N; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + 2 * N);
int res = WMAX * NMAX;
for (int i = 1; i < 2 * N; i++)
for (int j = i + 1; j <= 2... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-2, -2, 2, 2};
int dy[] = {2, -2, -2, 2};
long long toInt(string s) {
stringstream aa(s);
long long k;
aa >> k;
return k;
}
string toString(long long t) {
stringstream y;
y << t;
return y.str();
}
int gcd(int a, int b) {
if (!b)
return a;
e... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100, INF = 2009000999;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long a[N], opt[N];
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
int l90 = 0, l1440 = 0;
cin >> a[0];
opt[0] = 20;
cout << 20 << endl;
for (int i = 1; i < n; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long calc(int x1, int y1, int x2, int y2) {
return (abs(x1 - x2) + abs(y1 - y2));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, h, l, u, q;
cin >> n >> h >> l >> u >> q;
int a, b, x, y;
long long dis;
while (q--) {
dis = 0;
... | 2 |
#include <bits/stdc++.h>
int main() {
int t, n;
long s1, s2;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
s1 = 0;
s2 = 0;
scanf("%d", &n);
for (int j = n / 2; j < n; j++) {
s1 += pow(2, j);
}
for (int j = 1; j < n / 2; j++) {
s2 += pow(2, j);
}
s2 += pow(2, n);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int prime[123456];
vector<int> v;
int dp[300][1200][20], tak[50][1200], w[50], cost[50], d, t, n, k;
int foo(int i, int val, int c) {
int p1, p2;
if (c > k || i >= v.size()) return 0;
if (c == k) return val == n ? 1 : 0;
if (dp[i][val][c] != -1) return dp[i][val][c]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dis[105], rdis[105];
double k[105], k2[105];
vector<int> nei[105];
int n, m;
void bfs(int s, int d[], double f[]) {
queue<int> q;
q.push(s);
d[s] = 0;
f[s] = 1;
while (!q.empty()) {
int h = q.front();
q.pop();
for (int i = 0; i < nei[h].size(); i++... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> mp;
string str;
long long int p[110], a[110];
long long int n, m, mn = 0, mx = 0;
cin >> n >> m;
cin.ignore();
for (int i = 0; i < n; i++) {
cin >> p[i];
cin.ignore();
}
for (int i = 0; i < m; i++) {
getline(cin, s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9 + 7;
const long long int mod = 998244353;
void solve() {
int n, q;
cin >> n;
vector<long long int> ar(n);
long long int sum = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
sum += ar[i];
}
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15 + 7;
const long long MAX = 1e5;
const long long MOD = 1e9 + 7;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<pair<long long, long long> > vii;
typedef vector<vii> vvii;
typedef vector<bool> vb;
const long long maxn = 5005, m... | 16 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
vector<ii> find(vector<int>& val, bool rev) {
vector<ii> res;
for (int i = 0; i < val.size(); i++) {
if (val[i] == -1) return vector<ii>();
if (rev)
res.emplace_back(i, val[... | 7 |
#include <bits/stdc++.h>
int main() {
int a = 0, b;
char c[1001], d[1001];
gets(c);
while (c[a] != '.') {
d[a] = c[a];
a++;
}
d[a] = '\0';
if (c[a - 1] == '9')
printf("GOTO Vasilisa.\n");
else if (c[a + 1] < '5')
puts(d);
else {
d[a - 1] += 1;
puts(d);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<complex<double> > fft(vector<complex<double> > v, bool rev = false) {
int n = v.size(), i, j, m;
for (i = 0, j = 1; j < n - 1; j++) {
for (int k = n >> 1; k > (i ^= k); k >>= 1)
;
if (i > j) swap(v[i], v[j]);
}
for (int m = 2; m <= n; m *= 2) {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s, s2;
while (cin >> s1 >> s) {
int f = 0, l = s.size();
for (int i = 0; i < l; i++)
if (s1[i] < s[i]) {
f = 1;
break;
} else
s2.push_back(s[i]);
if (f)
cout << "-1" << endl;
else
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long n, m;
cin >> n >> m;
long long cnt = 0;
for (long(i) = 0; (i) < (n); (i)++) {
for (long(j) = 0; (j) < (m); (j)++) {
if ((i + 1 + j + 1) % 5 == 0) {
cnt += (m - (j + 1)) / 5;
++cnt;
break;
}
}
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxk = 51;
struct matrix {
bool e[maxk][maxk];
int sz;
void print() {
for (int i = 0, _n = (sz); i < _n; i++) {
for (int j = 0, _n = (sz); j < _n; j++) {
printf("%d", e[i][j]);
}
printf("\n");
}
printf("\n");
}
};
matr... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = (long long)1e5 + 8;
const long long MOD = (long long)1e9 + 7;
int main() {
int i, j, k;
long long M, N, x, y, p, q;
long long K;
cin >> N >> M >> K;
string b[N];
char st[MAXN];
for (i = 0; i < N; i++) {
scanf("%s", st);
b[i].assi... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct ed {
int u, v, cost, idx;
ed() {}
ed(int uu, int vv, int cc, int idx) : u(uu), v(vv), cost(cc), idx(idx) {}
bool operator<(const ed& a) const { return cost < a.cost; }
};
struct edge {
int next, cost;
edge() {}
edge(int a, int c) : next(a), cost(c) {}
}... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long l, r, k, ans = 1;
cin >> l >> r >> k;
bool flag = false;
while (ans <= r) {
if (ans >= l && ans <= r) {
printf("%lld ", ans);
flag = true;
}
if (r / ans < k) break;
ans = ans * k;
}
if (flag == false) c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, q, ans, t, i, j, f1[1001], f2[1001], a[1001][1001];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) ans += (a[i][j] & a[j][i]);
an... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
string a, b;
cin >> a >> b;
if (a == b)
cout << "-1";
else
cout << max(a.size(), b.size());
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
bool ok = true;
stringstream ss;
const long long N = (long long)1e9 + 7;
long double ans[1000007];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long test;
cin >> test;
while (test--) {
long long a, b;
cin >> a >> b;
... | 0 |
#include <bits/stdc++.h>
const int N = 210;
int n, t, m;
long long x, a[N], b[N], c[N], f[N][N][2], g[N][N][2];
inline void upd(long long &a, long long b) {
if (b < a) a = b;
}
inline long long ceildiv(long long a, long long b) { return (a + b - 1) / b; }
int main() {
memset(f, 63, sizeof(f)), memset(g, 63, sizeof(... | 26 |
#include <bits/stdc++.h>
using namespace std;
queue<long long> q;
map<pair<long long, long long>, long long> m;
pair<long long, long long> p;
long long n, u, v, cnt[1000000], a[1000000], pos;
signed main() {
scanf("%lld", &n);
for (long long i = 1; i < n; i++) {
scanf("%lld %lld", &u, &v);
cnt[u]++;
cnt... | 9 |
#include <bits/stdc++.h>
using namespace std;
string sconvert(long long int n) {
stringstream ss;
ss << n;
string str = ss.str();
return str;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second > b.second);
}
template <typename T>
void imax(T &x, T y) {
x = max(x, y);
}
tem... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int qr() {
int f = 0, fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + c - 48;
c = getchar();
}
return f * fu;
}
int T, n;
int calc(... | 3 |
#include <bits/stdc++.h>
using namespace std;
set<int> b[100020];
vector<pair<int, int> > a[100020];
int d[100020];
int v[200020];
priority_queue<pair<int, int> > q;
int n, m, x, y, z;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &x, &y, &z);
a[x].push_back(pair<int, int... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1000005;
vector<int> g[maxn];
int pa[maxn];
int dep[maxn];
vector<int> v[maxn];
void dfs(int now) {
v[dep[now]].push_back(now);
for (auto &i : g[now]) {
if (dep[i]) {
continue;
}
pa[i] = now;
dep[i] = dep[n... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200500;
int n;
string s1, s2;
long long s[maxn];
double get(const vector<int> &a, const vector<int> &b) {
for (int i = 0; i < (int)(n); i++) {
s[i] = b[i] ? (i + 1) : 0;
if (i) s[i] += s[i - 1];
}
double res = 0;
for (int i = 0; i < (int)(n)... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline string GetString() {
char GS[1000005];
scanf("%s", GS);
string ret = GS;
return ret;
}
inline char getc() {
char c = ' ';
while (c == ' ' || c == '\t' || c == '\r' || c == '\n') c = getchar();
return c;
}
int n, m, i;
vector<int> adj[100005];
int v[1000... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct nod {
int l, r;
mutable long long v;
inline bool operator<(const nod b) const { return l < b.l; }
nod(int a, int b = -1, long long c = -1) { l = a, r = b, v = c; }
};
int n;
set<nod> li;
set<nod>::iterator split(int p) {
set<nod>::iterator a = li.lower_boun... | 18 |
#include <bits/stdc++.h>
const int N = 220;
const long long mod = 998244353;
using namespace std;
int n;
int m;
int a[N][N];
pair<string, string> solve(int k) {
string s{};
string t{};
s.reserve(m);
t.reserve(m);
for (int i = 1; i <= m; i++) {
int need = (i <= k) ^ 1;
int one = a[1][i] != need;
t ... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct directie {
int x, y;
};
directie v[1008];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", &v[i].x, &v[i].y);
v[n + 1] = v[1];
v[n + 2] = v[2];
v[n + 3] = v[3];
int cate = 0;
for (int i = 1; i <= n; i++) {
if (v[i + ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> m;
vector<int> used(101000, 1);
int r = 0;
for (int i = 2; i < used.size(); ++i) {
if (used[i] > 1) continue;
m[i] = r;
used[i] = i;
++r;
for (int j = i * i; j < used.size(); j += i) used[j] = i;
}
int n, k;
cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct node {
int nxt, ed, len;
} e[2 * N];
int head[N], num, vis[2 * N], p[40], ans, n, used[N], dp[N];
vector<int> v;
void add(int x, int y, int z) {
e[num].ed = y;
e[num].len = z;
e[num].nxt = head[x];
head[x] = num++;
}
void dfs(int u, i... | 15 |
#include <bits/stdc++.h>
template <class T>
void smin(T& a, T val) {
if (a > val) a = val;
}
template <class T>
void smax(T& a, T val) {
if (a < val) a = val;
}
using namespace std;
int a[1000010], n;
string s;
int c;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
... | 1 |
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-'))
;
if (c == '-') {
nega = 1;
c = getchar();
}
x = c - 48;
while (isdigit(c = getchar())) x = x * 10 + c - 48;
if (nega) x = -x;
}
template <typename T... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void _R(T &x) {
cin >> x;
}
template <typename T>
void _R(vector<T> &x) {
for (auto it = x.begin(); it != x.end(); it++) {
_R(*it);
}
}
void R() {}
template <typename T, typename... K>
void R(T &head, K &...tail) {
_R(head);
R(tail...);
}... | 8 |
// frequencyproblem.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
long long n;
cin >> n;
long long *a= new long long[n];
long long *b = new long long[n];
for (in... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, intersection[500][100100], HeavyN[100100];
bool Light[100100], Heavyin[500][100100];
long long ara[100100], HHupdate[500], HLupdate[500], HeavySum[500];
vector<int> Set[100100], HeavyS;
int main() {
cin >> n >> m >> q;
int sq = sqrt(n);
for (int i = 0; i ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a + c < b) {
cout << "-";
return 0;
}
if (b + c < a) {
cout << "+";
return 0;
}
if (a == b && c == 0) {
cout << "0";
return 0;
}
cout << "?";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
if (a % 2 != 0)
cout << 0 << endl;
else {
int b = a / 2;
if (b % 2 == 0)
cout << (b - 2) / 2 << endl;
else
cout << (b - 1) / 2 << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
long long ans = 1;
while (p) {
if (p & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
p /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) r... | 18 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y, vl;
bool operator<(const point &temp) const { return vl < temp.vl; }
};
point pt[110001];
int n, l[22222], r[22222];
double a, ans;
int main() {
int i, j, s, p, q;
double xx, yy, k, b, dis;
scanf("%d%lf", &n, &a);
for (i = 0; i < n; i... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n;
int flag[10];
int chk(int x) {
while (x > 0) {
if (flag[x % 10] == 1) return 1;
x /= 10;
}
return 0;
}
int main() {
int t;
cin >> n;
for (int(i) = 0; (i) < (10); (i)++) flag[i] = 0;
int cop = n;
while (cop > 0) {
int dig = cop % 10;
fl... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n;
d = n / 2;
cout << d << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000003;
int ppp[MAXN];
int phi[MAXN];
int fen[MAXN];
void upd(int x) {
for (int s = x; s < MAXN; s += s & -s) fen[s]++;
}
int que(int x) {
int ans = 0;
for (int s = x; s > 0; s -= s & -s) ans += fen[s];
return ans;
}
int main() {
ios::sync_with_... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
int a[10][MAXN];
int b[10][MAXN];
int dp[MAXN] = {};
int n, m;
bool check(int x, int y) {
for (int i = 0; i < m; i++) {
if (b[i][x] < b[i][y]) return 0;
}
return 1;
}
int main() {
scanf("%d%d", &n, &m);
int ans = 0;
for (int i = 0... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, u, v;
int m, p;
long long cal(long long l, long long r, long long x, long long y, long long a,
long long d) {
long long s = r - l + 1;
if ((v < a) || (u > a + (s - 1) * d)) return 0;
if ((l == x) && (r == y)) {
long long h = a + ((max(u,... | 17 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int BUFFER_SIZE = 1 << 15;
char input_buffer[BUFFER_SIZE];
int input_pos = 0, input_len = 0;
char output_buffer[BUFFER_SIZE];
int output_pos = 0;
char number_buffer[100];
uint8_t lookup[100];
void _update_input_buffer() {
input_len = fread(input_buffe... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxx = 3e5 + 10;
char s[maxx];
int num[maxx][26];
int main() {
scanf("%s", s + 1);
int n = strlen(s + 1);
for (int i = 1; i <= n; i++) {
num[i][s[i] - 'a']++;
for (int j = 0; j < 26; j++) {
num[i][j] += num[i - 1][j];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 2... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
vector<long long> v[N];
vector<long long> vcol[105];
vector<long long> dis[N];
void bfs(long long x, long long* d) {
queue<long long> q;
d[x] = 1;
q.push(x);
while (!q.empty()) {
long long x = q.front();
q.pop();
for (int y : ... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime[400];
vector<int> prime;
vector<int> factor[12005];
int primeCnt[80];
void make_prime() {
for (int i = 0; i < 400; i++) isPrime[i] = true;
for (int i = 2; i < 400; i++) {
if (isPrime[i]) {
for (int j = i * i; j < 400; j += i) isPrime[j] = false;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const unsigned long long INF = 0x3f3f3f3f3f3f3f3fLL;
unsigned long long c, hr, hb, wr, wb;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
return b == 0 ? a : gcd(b, a % b);
}
unsigned long long lcm(unsigned long long a, un... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, a[maxn][maxn];
vector<int> tmp, r[maxn], c[maxn];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]), r[i].push_back(a[i][j]), c[j].push_back(a[i][j]);
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 110;
char m[MAXN][MAXN];
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (n == 5) {
printf(">...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n");
return 0;
} else if (n == 3) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int line, a, b;
cin >> line;
while (line--) {
cin >> a >> b;
if (gcd(a, b) == 1) {
cout << "finite" << endl;
} else {
cout << "infinite" << endl;
}
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void merge(int a[], int s1, int e1, int s2, int e2) {
int i = s1, j = s2, k = 0;
int n1 = e1 - s1 + 1;
int n2 = e2 - s2 + 1;
int *ans = new int[n1 + n2];
while (i <= e1 && j <= e2) {
if (a[i] < a[j]) {
ans[k++] = a[i++];
} else {
ans[k++] = a[j... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.