solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
char s[405];
int k, len, ans;
bool ok(int x, int l) {
int i, j;
for (i = 1; i <= l; i++) {
if (s[x] != s[x - l] && s[x] != '#' && s[x - l] != '#') return false;
x--;
}
return true;
}
int main() {
int i, j;
scanf("%s", s);
len = strlen(s);
scanf("%d",... | 7 |
#include <bits/stdc++.h>
using namespace std;
int d[10001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
d[u]++;
d[v]++;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += ((d[i]) * (d[i] - 1)) / ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200010];
int main() {
scanf("%d", &n);
int tmp = 0, s = 0;
bool f = false, f2 = false;
int mx = -2e9;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] < 0) {
s++;
mx = max(mx, a[i]);
}
if (a[i]) {
if (!tmp) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
double s = 0.0;
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y;
s += y;
}
s /= n;
cout << s + 5 << endl;
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e5 + 9;
vector<long long> adj[MX], ind;
long long dis[MX], mrk[MX], used[MX], par[MX];
void CYCLE(long long u, long long v) {
cout << 2 << endl << dis[u] - dis[v] + 1 << endl;
while (u != v) cout << u << " ", u = par[u];
cout << v;
exit(0);
}
v... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline istream &operator>>(istream &str, pair<T, U> &p) {
return str >> p.first >> p.second;
}
template <class T, class U>
inline ostream &operator<<(ostream &str, pair<T, U> &p) {
return str << p.first << " " << p.second << endl;
}
template ... | 16 |
#include<bits/stdc++.h>
using namespace std;
int t;
string a;
int vis[200];
int main() {
cin >> t;
while (t--) {
cin >> a;
int len = a.size();
if (len == 1) {
if (a[0] == 'a') cout << "YES" << endl;
else cout << "NO" << endl;
continue;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int par[MAX][17];
int toyWith[MAX];
int level[MAX];
vector<int> adj[MAX];
int sz[MAX];
int setLevel(int x, int l = 0) {
level[x] = l;
sz[x] = 1;
for (int i = 0; i < adj[x].size(); i++) sz[x] += setLevel(adj[x][i], l + 1);
return sz[x];
}
bool... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
scanf("%d", &a);
scanf("%d", &b);
int mnum = 0, t = a;
while (t > 0) {
mnum = max(mnum, t % 10);
t = t / 10;
}
t = b;
while (t > 0) {
mnum = max(mnum, t % 10);
t = t / 10;
}
mnum++;
t = 1;
int a1 = 0, b1 = 0;
wh... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mod2 = 67280421310721ll;
int n, m;
int allocated = 0;
map<int, long long int> rem;
map<long long int, int> same;
long long fact[1000005];
long long int power[1000005];
int l[1000005];
long long mulmod(long long a, long long b, long long c) {
long long x = 0, y =... | 11 |
#include <bits/stdc++.h>
char line[100000], message[100000], kind;
int num, result;
int main() {
while (scanf("%[^\n]\n", line) != EOF) {
char *now = line;
while (now[0] != '+' && now[0] != '-' && now[0] != ':') now++;
switch (now[0]) {
case '+':
num++;
break;
case '-':
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
double cnt = 0;
cin >> str;
for (long long i = str.size() - 1; i >= 1; i--) {
if (str[i] >= 48 && str[i] <= 57) {
if (str[i - 2] == 46) {
cnt += ((str[i] - '0') * 0.01 + (str[i - 1] - '0') * 0.1);
i = i - 2;
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int t;
cin >> t;
while (t--) {
long long int a, b, c, d, x, y, x1, x2, y1, y2, e, first, flag = 0,
slag = 0;
cin >> a >> b >> c >> d;
cin >> x >> y >> x1 >> y1 >> x2 >> ... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b[1005], c[10005], x, w, i;
scanf("%d", &a);
x = 0;
w = 0;
for (i = 0; i < a; i++) {
scanf("%d", &b[i]);
w = b[i] + w;
}
for (i = 0; i < a; i++) {
scanf("%d", &c[i]);
x = x + c[i];
}
if (x <= w)
printf("Yes");
else
printf("No");
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void dbvar() { cerr << "]" << endl; }
template <class H, class... T>
void dbvar(H h, T... t) {
cerr << to_string(h);
if (sizeof...(t)) cerr << ", ";
dbvar(t...);
}
const int INF = (int)(1e9);
const long long int INFL = (long long int)(1e18);
const long double pi = aco... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[101];
long long b[101];
long long mat[101][101];
long long mo = 100000000000000007LL;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> mat[i][j];
for (int i... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[10] = {0};
int arr_num[10] = {0};
int t;
string line;
cin >> t;
getline(cin, line);
getline(cin, line);
for (int i = 0; i < line.size(); i++) {
if (line[i] == '2' || line[i] == '5')
arr[2]++;
else if (line[i] == '6' || line... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n * n % 2 == 0) {
for (int i = 1, j = n * n; i <= j, j >= i; i++, j--)
cout << i << " " << j << "\n";
return 0;
} else {
for (int i = 1, j = n * n; i<j, j> i; i++, j--)
cout << i << " " << j << "\n";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool used[105];
int main() {
int n, m;
cin >> n >> m;
string s[105];
bool flag;
int c = 0;
for (int i = 1; i <= n; i++) {
cin >> s[i];
}
for (int i = 0; i < m; i++) {
flag = false;
for (int j = 2; j <= n; j++) {
if (used[j] == false and s[j... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[40];
int main() {
iostream::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
if (n == 1) {
cout << "Yes";
return 0;
}
for (int i = 0; i < n; i++) {
a[s[i] - 'a']++;
if (a[s[i] - 'a'] > 1) {
cout << "Yes";
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, s, m, k, j, si, sj, all;
char c;
long long a[507][507];
void lab(long long x, long long y) {
if (all == s) return;
if (a[x][y] == 0 && x > 0 && x <= n && y > 0 && y <= m) {
all++;
a[x][y] = 2;
lab(x + 1, y);
lab(x - 1, y);
lab(x, y + ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long start = 1;
long long end = 1e9;
long long ans = LLONG_MAX;
while (start ... | 9 |
#include <bits/stdc++.h>
long long k, p, ans;
long long getk(long long v) {
long long ret = 0, bit = 1;
for (long long i = v; i > 0; i /= 10, bit *= 10) ret = ret * 10 + i % 10;
ret += v * bit;
return ret;
}
int main(void) {
scanf("%I64d%I64d", &k, &p);
for (long long i = 1; i <= k; i++) ans = (ans % p + ge... | 5 |
#include <bits/stdc++.h>
using namespace std;
double PI = 4.00 * (atan(1));
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int fun[n + 1];
set<long long int> s1;
for (long long int i = 1; i <= n; i++) {
cin >> fun[i];
}
bool check = t... | 9 |
#include <bits/stdc++.h>
using namespace std;
int chh;
const long long N = 1000005;
inline void in(int &t) {
int n = 0, s = 1;
char ch = getchar();
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') s = -1, ch = getchar();
while (ch >= '0' && ch <= '9') n = n * 10 + ch - '0', ch = getc... | 11 |
#include <bits/stdc++.h>
template <typename T>
void scan(T &x) {
x = 0;
bool _ = 0;
T c = getchar();
_ = c == 45;
c = _ ? getchar() : c;
while (c < 48 || c > 57) c = getchar();
for (; c < 48 || c > 57; c = getchar())
;
for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15);
x =... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long>>> powers(200005);
void factorize(long long n) {
for (long long i = 2; i < n; i++) {
if (powers[i].empty()) {
for (long long j = i; j < n; j += i) {
long long q = j;
long long power = 0;
while (q % ... | 8 |
#include <bits/stdc++.h>
int mod = 1000000007;
using namespace std;
using namespace std;
vector<vector<int> > adj(400005);
int dp[400005];
int parent[400005];
int half;
int cntr = -1;
int n;
int v1 = -1, v2 = -1;
int ans[400005];
void dfs1(int v, int p, int n) {
dp[v] = 1;
bool dcn = true;
vector<int>::iterator i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-12;
const int maxn = 100000 + 123;
int n;
string type[maxn];
int a[maxn];
void ReadData() {
cin >> n;
memset(a, -1, sizeof(a));
for (int i = 1; i <= n; i++) {
cin >> type[i];
if (type[i] == "add" || type[i] == "del") {
cin >> a... | 15 |
#include <bits/stdc++.h>
using namespace std;
void func(void) {
freopen("input.c", "r", stdin);
freopen("output.c", "w", stdout);
}
void print(vector<long long> &v) {
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++) {
printf("%lld ", v[i]);
}
printf("\n");
}
void print(vector<pair<long long,... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
multiset<string> a, b;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
a.insert(s);
}
for (int i = 0; i < n; i++) {
string s;
cin >> s;
b.insert(s);
}
int count = 0;
for (auto p : b) {
for (auto q... | 4 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
long long tc = 1;
while (tc--) {
long long n;
cin >> n;
unordered_map<long long, long long> cnt;
vector<long long> a(n), b(n - 1);
for (auto &x : a) {
cin >> x;
cnt[x]++;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N = 1, n, m, i, j, x, y, k, type, L, R;
int a[400005], b[400005];
int diff[400005];
int tree[800005];
int main() {
cin >> n >> m;
for (i = 1; i <= n; i++) cin >> a[i];
for (i = 1; i <= n; i++) cin >> b[i];
while (N <= n) N <<= 1;
for (i = 1; i <= m; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
cin >> s;
int ok = 1;
if (n == 1) {
if (s[0] == '0')
cout << "No";
else
cout << "Yes";
return 0;
}
if (s[0] == '0' && s[1] == '0') ok = 0;
if (s[0] == '1' && s[1] == '1') ok = 0;
if (s[s.size() ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int fx[] = {0, 0, 1, -1, -1, 1, -1, 1};
int fy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int arr[55][55];
int main() {
int n, m, a, b;
scanf("%d%*c", &n), scanf("%d%*c", &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d%*c", &arr[i][j]);
... | 4 |
#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, m;
string s;
cin >> n >> m;
cin >> s;
vector<long long int> vec;
for (long long int i = 0; i < s.size(); i++) {
if (s[i] == '0') vec.push_back(i);
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long m = 0, n = 0, k = 0, temp = 0;
long mi = 1000000003;
cin >> n >> m >> k;
long roads[m][3];
long stor[n];
for (int i = 0; i < m; i++) cin >> roads[i][0] >> roads[i][1] >> roads[i][2];
for (int i = 0; i < n; i++) stor[i] = 0;
for (int i = 0; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long hashval(const pair<int, int> &v) {
return v.first * 239017LL + v.second;
}
int main() {
unordered_map<int, vector<int> > by_x, by_y;
unordered_set<long long> Hashes;
int x, y, n;
cin >> n;
vector<pair<int, int> > pts(n);
for (int i = 0; i < n; i++) {... | 15 |
#include <bits/stdc++.h>
using namespace std;
int t;
long long x, y;
int main() {
cin >> t;
while (t > 0) {
t--;
scanf("%lld%lld", &x, &y);
x -= y;
if (x == 1)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int const maxn = (int)1e5 + 11;
int const inf = (1 << 30) - 1;
struct data {
char first, second;
long long num;
data() {}
data(char _f, char _s, long long _num) {
first = _f;
second = _s;
num = _num;
}
data operator+(data o) {
data res = data(fir... | 12 |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define fors(i, a, b) for(int i = (a); i < (b); ++i)
#define all(vec) vec.begin(),vec.end()
using namespace std;
int n;
#define P pair<int,int... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, k;
while (cin >> n >> k) {
long long min_val = (k == 0 || k == n ? 0 : 1);
long long max_val = (3 * k > n ? n - k : 2 * k);
cout << min_val << " " << max_val << '... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long x[100001];
long long dist(int x1, int x2) { return abs(x1 - x2); }
int main(int argc, char **argv) {
long long n, a;
cin >> n >> a;
if (n == 1) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; i++) cin >> x[i];
sort(x + 1, x + 1 + n);
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
long long A, B;
int N;
long long eval(int l, int r) {
return A * (r - l + 1) + B * (r + l - 2) * (r - l + 1) / 2;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> A >> B >> N;
for (int i = 0; i < N; ++i) {
long long l, t, m;
cin >... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long p) {
if (p == 0) return 1;
if (p == 1) return a;
long long tmp = power(a, p / 2);
if (p % 2)
tmp = ((tmp * tmp) % 1000000007) * a;
else
tmp *= tmp;
return tmp % 1000000007;
}
long long NUM;
char C;
bool TURN;
long l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ans, sum, x, n, q;
int main() {
scanf("%d %d", &n, &x);
sum = 0;
for (int i = 0; i < n; i++) {
cin >> q;
sum += q;
}
sum = abs(sum);
ans = sum / x;
if (sum % x != 0) ans++;
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
const long long maxn = 1e6 + 10;
long long pref[maxn];
long long suf[maxn];
long long res = 1e9;
int32_t main() {
string s;
cin >> s... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[100001];
long long int v = 1000000007;
int main() {
string s;
cin >> s;
long long int l = s.length();
dp[0] = 1;
dp[1] = 1;
dp[2] = 2;
for (int i = 3; i <= l; i++) {
dp[i] = (dp[i - 1] % v + dp[i - 2] % v) % v;
}
bool invalid = false;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto vv : V) os << vv << ",";
return os << "]";
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> books(m);
for (int i = 0; i < n; i++) {
int c;
cin >> c;
books[c - 1]++;
}
int choice = 0;
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
choice += books[i] * books[j];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e3 + 10;
long long sumb[maxn], N;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
string str;
cin >> str;
N = str.size();
for (register long long i = 1; i <= N; ++i) {
sumb[i] = sumb[i - 1] + (str[i - 1] == 'b');
}
long l... | 7 |
#include <bits/stdc++.h>
using namespace std;
int count(char str[]) {
int start = 0;
char last;
last = str[0];
start = 1;
for (int i = 1; i < strlen(str); i++) {
if (str[i] != last) {
last = str[i];
start++;
}
}
return start;
}
char flip(char a) {
if (a == '1') return '0';
if (a ==... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string s1, s2;
for (int i = 0; i < n; i++) {
s1.push_back(s[i]);
}
for (int i = 2 * n - 1; i >= n; i--) {
s2.push_back(s[i]);
}
sort(s1.begin(), s1.end());
sort(s2.begin(), s2.end());
bool fla... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
return (b == 0) ? abs(a) : gcd(b, a % b);
}
template <typename T>
inline T sqr(T x) {
return x * x;
}
inline void open() {
freopen("test.inp", "r", stdin);
freopen("test.txt", "w", stdout);
}
int main() {
int dd, res = 0, n,... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int CNT_STEP = 28;
const int CNT_NUMBERS = 6;
const int MAX_LEN = 20;
const int step[CNT_STEP][CNT_NUMBERS] = {
{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 4}, {0, 0, 0, 0, 0, 7},
{0, 0, 0, 0, 4, 4}, {0, 0, 0, 0, 4, 7}, {0, 0, 0, 0, 7, 7},
{0,... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const long long LINF = 4611686018427387903;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 9;
signed main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
pair<int, int> cs[3];
for (int i = 0; i < 3; i++) cin >> cs[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n;
int arr[N], used[N];
bool tip[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> tip[i];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
used[arr[i]]++;
}
if (n == 1) {
cout << 1 << " " << 1 << endl;
return ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, i, j, k, x, y, z, l, r, mid, ans, mod = 1e9 + 7, g, m;
long long a[40][40];
char ch;
string s, st;
vector<long long> v[30][30], u;
void f1(int i, int j, int x, long long y) {
if (i == n || j == m) return;
y ^= a[i][j];
if (x == z) {
v[i][j].push_ba... | 13 |
#include <bits/stdc++.h>
int n;
char data[200010];
char out[200010];
int main() {
scanf("%d", &n);
scanf("%s", data);
int cnt = 0;
for (int i = 0; i < n; i++) {
if (i == 0 || out[i - 1] != data[i]) {
out[i] = data[i];
continue;
}
cnt++;
if (out[i - 1] != 'R' && data[i + 1] != 'R')
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int A[200005], S[30][200005], C[30][200005];
long long int n;
vector<long long int> ans;
bool parity = true;
void addition(vector<long long int> v) {
for (int i = 0; i < v.size(); i++) {
long long int temp = ans[i] + v[i];
if (temp >= 10) {
ans[i] ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long aib[100010];
int n;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> aib[i];
long long m, w, h;
cin >> m;
while (m--) {
cin >> w >> h;
long long maxim = 0;
while (w > 0) {
if (aib[w] > maxim... | 7 |
#include <bits/stdc++.h>
using namespace std;
int p[200005], n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int t;
scanf("%d", &t);
p[t] = i;
}
long long ret = 0;
for (int i = 1; i < n; i++) {
ret += abs(p[i + 1] - p[i]);
}
cout << ret;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-12;
int mem[1001][1001];
int to[1001][1001];
int solve(string &s, string &t, int i, int j) {
if (i == (int)s.size() || j == (int)t.size())
return ((int)s.size() - i) + ((int)t.size() - j);
int &ret = mem[i][j];
if (ret < 0) {
ret =... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const int maxn = 4e5 + 5;
const int maxm = 4e5 + 10;
const int mod = 1e9 + 7;
int pos[4][maxn];
struct node {
int x, y;
int id;
} a[maxn];
int ans[maxn];
int res[10];
bool cmp1(node A, node B) {
if (A.x == B.x) return A.y < B.y;
retu... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, char> > s, t, u;
long long lps[200005];
void computelps() {
long long i, j, k;
long long n1, n2;
n2 = u.size();
lps[0] = 0;
i = 1;
j = 0;
while (i < n2) {
if (u[i] == u[j]) {
lps[i] = j + 1;
i++;
j++;
} else {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
string flag = "NO";
for (int j = 0; 3 * j <= x; ++j) {
if ((x - 3 * j) % 7 == 0) {
flag = "YES";
break;
}
}
cout << flag << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool mycomp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.second < b.second);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
long long n;
cin >> n;
lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int nneg = a + b;
int subz = b + c;
int grez = a + d;
if (grez && (nneg % 2))
cout << "Ya ";
else
cout << ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
if (n <= 8)
cout << 0 << '\n';
else if (n == 9 || n == 10)
cout << 1 << '\n';
else {
if (n % 10 == 9)
cout << (n / 10) + 1 << '\n';
els... | 0 |
#include <bits/stdc++.h>
using namespace std;
int rui[2005][2005] = {}, n, m;
char first[2005][2005];
int main() {
srand((unsigned int)time(NULL));
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", &first[i]);
int lx = 2000000000, ly = 2000000000, rx = -2000000000, ry = -2000000000;
for (int i =... | 13 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int ara[n][n], i, j, res[n], a = n;
for (i = 0; i < n; i++) {
res[i] = 0;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &ara[i][j]);
if (ara[i][j] == 1) {
if (res[i] == 0) {
res[i] = 1;
... | 1 |
#include <bits/stdc++.h>
const int maxn = 1e6 + 100;
int vis[maxn];
int p[maxn];
int b[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
int sum = 0, ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
sum += b[i];
}
if (sum % 2 == 0) ans++;
int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<string> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
int m = s[0].size();
for (int j = 0; j < m; ++j) {
set<char> st;
for (int i = 0; i < n; ++i) {
st.insert(s[i][j]);
}
if (st.size() != 1) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
long long x;
long long k = a - 1;
if (k % 4 == 0)
x = k;
else if (k % 4 == 1)
x = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[111][111];
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
if ((a[i][j] ^ i + j) & 1) ++a[i][j];
}
for (int i = 1; i <= n... | 12 |
#include <bits/stdc++.h>
template <typename T>
bool chkmin(T &a, T b) {
return (b < a) ? a = b, 1 : 0;
}
template <typename T>
bool chkmax(T &a, T b) {
return (b > a) ? a = b, 1 : 0;
}
long long ksm(long long a, long long b) {
if (b == 0) return 1;
long long ns = ksm(a, b >> 1);
ns = ns * ns % 998244353;
if... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n;
pair<string, string> s[1010];
map<pair<string, string>, bool> ms;
pair<string, string> ans[1010];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
string s1, s2;
cin >> s1 >> s2;
s[i] = make_pair(s1, s2);
ms[s[i]] = false;
}
int t = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int MAXN = 105;
int n, a, b;
int main(int argc, char const *argv[]) {
scanf("%d", &n);
while (n--) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y)
a++;
else if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, a, b, c, d;
vector<int> g[5050];
int par[5050];
int cnt[5050];
vector<int> v;
int gettype(int x) {
int last = -1;
while (x != 0) {
last = x;
x = par[... | 21 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long N = 105;
long long d[N];
void dfs(long long node, long long par, long long depth,
vector<vector<long long>>& graph) {
++d[depth];
for (auto i : gra... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
vector<int> fact, inv_fact, inv;
int add(int a, int b) {
int x = a + b;
if (x >= MOD) x -= MOD;
if (x < 0) x += MOD;
return x;
}
int sub(int a, int b) { return add(a, -b); }
int mult(int a, int b) { return 1LL * a * b % MOD; }
int pow_mod(... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005, maxm = 30010;
int timer, vis[maxn], tin[maxn], low[maxn];
long long weight[maxm];
pair<int, int> edge[maxm];
vector<pair<long long, pair<int, int>>> graph[maxn];
vector<int> path, bridges;
bool findpath(int u, int t) {
if (u == t) return 1;
vis[u]... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline int rint() {
int a;
scanf("%d", &a);
return a;
}
inline long long rll() {
long long a;
scanf("%lld", &a);
return a;
}
inline double rdouble() {
double a;
scanf("%lf", &a);
return a;
}
long long gcd(long long a, long long b) { return (b) ? gcd(b, a %... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 4e18;
const int inf = 2e9;
const double eps = 1e-13;
const int N = 1e5;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<int> prime;
bool is[N];
int main(v... | 2 |
#include <bits/stdc++.h>
using namespace std;
char result[55][55];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
string s;
cin >> n >> s;
vector<int> ww;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
resul... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s, p;
cin >> s;
cin >> p;
int cnt = 0;
for (int i = 0; i < n... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
const long long MOD = 1e9 + 7;
long long s[N], t[N];
long long dp[N];
long long bin_pow(long long a, long long n) {
if (n == 0) return 1;
if (n & 1) {
return (a * bin_pow(a, n - 1)) % MOD;
} else {
long long temp = bin_pow(a, n / 2);
ret... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
string s1, s2;
map<string, string> ma1;
map<string, string> ma2;
int main() {
while (~scanf("%d", &n)) {
ma1.clear();
ma2.clear();
while (n--) {
cin >> s1 >> s2;
if (ma2.find(s1) == ma2.end()) {
ma1[s1] = s2;
ma2[s2] = s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
long long ans[maxn];
struct node {
int v, x;
node() {}
node(int a, int b) { v = a, x = b; }
} mem[maxn << 1], *f[maxn], *now = mem;
int n, cnt, Cnt, rt;
int to[maxn], nxt[maxn], head[maxn], dep[maxn], md[maxn], son[maxn], fa[maxn];
bool vis[ma... | 19 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(i=a;i<=b;++i)
using namespace std;
const int N=1e5+10;
int T,n,i,st,l,r,a[N];
long long k,mi[100];
int main(){
scanf("%d",&T);
mi[0]=mi[1]=1;
fo(i,2,63) mi[i]=mi[i-1]<<1;
mi[64]=(mi[63]-1)*2;
while (T--){
scanf("%d%lld",&n,&k);
fo(... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& x : v) is >> x;
return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i) os << ' ' <... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, kd;
};
vector<node> g[1010];
int n;
int cmp1(node x, node y) { return x.y < y.y; }
int cmp2(node x, node y) { return x.y > y.y; }
int main() {
node tmp;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &tmp.x, &tmp.y);
tm... | 13 |
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
const int mod = 1e9 + 7;
int t, n, k;
int f[N][N][2];
int solve(int cur, int k, int dir) {
if (k == 1) return 1;
if (f[cur][k][dir] != -1) return f[cur][k][dir];
int ans = 2; //自己和复制体
if (dir == 1) { //正向
if (cur < n) ans +=... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:67108864")
using namespace std;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
const long long INF = 1000 * 1000 * 1000 + 9;
const int NMAX = 2 * 100 * 1000 + 3;
int n, m;
vector<int> l[NMAX];
vector<pair<int, bool> > x[NM... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
void solve() {
long long int n, k;
cin >> n >> k;
k = min(k, n / 2);
long long int ans = 0;
ans = (k * n) - ((k * (k + 1)) / 2) + ((k * (k - 1)) / 2) + k * (n - 2 * k);
cout << ans;
}
int main() {
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[200500];
set<int> ones;
set<int> zers;
vector<vector<int> > res;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
if (ones.empty()) {
res.push_back({i + 1});
zers.insert(res.size() - 1);
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct problem {
int p, t;
} pm[51];
int main() {
int n, c;
int point1 = 0, point2 = 0;
int t1[51];
int t2[51];
scanf("%d%d", &n, &c);
for (int i = 0; i < n; i++) {
scanf("%d", &pm[i].p);
}
for (int i = 0; i < n; i++) {
scanf("%d", &pm[i].t);
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isplus(vector<string> s, int i, int j) {
int h = s.size();
int w = s[0].length();
int k;
if (i - 1 < 0 || i + 1 >= h || j - 1 < 0 || j + 1 >= w) {
return false;
}
if (s[i - 1][j] == '.' || s[i + 1][j] == '.' || s[i][j - 1] == '.' ||
s[i][j + 1] ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, res = 1;
cin >> n >> m;
long long lim = 1;
for (int i = 0; i < m; i++) {
lim = (lim << 1) % 1000000009;
}
if (lim < n) lim += 1000000009;
for (long long i = lim - n; i < lim; i++)
res = (res * (i % 1000000009)) % 1000000009... | 5 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
long long int testCase;
cin >> testCase;
while (testCase--) {
long long int n;
cin >> n;
vector<int> vec(n + 1);
for (long long int i = 0; i < n; ++... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.