solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, ans = 99999999;
int z(int x, int y) {
if (y == 1) return x - 1;
if (x == 0) return 100000000;
if (y == 0) return 100000000;
if (x == y) return 100000000;
return z(y, x % y) + x / y;
}
int main() {
cin >> n;
if (n < 2) {
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef struct node {
double x;
double y;
double r;
} NODE;
NODE sta[3], ans[3];
double center_x, center_y;
bool comp(const NODE &x, const NODE &y) { return (x.r < y.r); }
bool cmp(const NODE &x, const NODE &y) { return (x.y < y.y); }
void output() {
int alpha, beta... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
string s[2000010];
const int way[4][2] = {0, 1, 0, -1, 1, 0, -1, 0};
int edgecnt[2000010];
queue<pair<int, int>> q;
void bfs() {
pair<int, int> tmp = q.front();
q.pop();
int i = tmp.first, j = tmp.second;
for (int k = 0; k < 4; k++) {
int ii =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b = 0, j;
cin >> n;
vector<int> v1;
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
int j = n / i;
v1.push_back(i);
v1.push_back(j);
b = b + 2;
if (i >= j) {
break;
}
}
}
cout << v1.at(b - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> data[100005];
int n, N, id[100005], vot[100005], f[100005], m;
vector<pair<int, int> > A[100005];
vector<int> B[100005];
int calc(int x) {
if (vot[0] + x == 0) return 2100000000;
int sum = 0, cost = 0;
for (int i = (int)1; i <= (int)m; i++) f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, temp1, temp2, temp3;
unsigned long long int cons = 998244353;
cin >> t;
for (int j = 0; j < t; j++) {
cin >> n;
if (n <= 998244353 * 2) {
if (n % 2) {
cout << 7;
n -= 3;
}
for (int i = 0; i < n / 2; i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n == 0) {
cout << "1";
return 0;
}
if (n == 1) {
cout << "4";
return 0;
}
long long t = 4;
long long i = 1, j = n - 1, r = 0;
while (i < n && j > 0) {
if ((i + 1) * (i + 1) + (j * j) <= n * n)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void gn(int &x) {
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
}
int T;
long long n, m, s, ans;
int p[1000010], tot, a[1000010], top, lim[1000010];
int id[1000010], cnt... | 3 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
using namespace std;
int main()
{
vector<char> ls;
int n;
while(true)
{
cin >> n;
if(n==0)break;
vector<int> key(n);
for(int i=0;i<n;i++)
cin >> key[i];
string s;
cin >> s;
string ans;
for... | 0 |
#include <iostream>
int main() {
int m, d;
std::cin >> m >> d;
int ans = 0;
for (int i = 1; i <= m; ++i)
for (int j = 22; j <= d; ++j)
if ((j % 10) >= 2 && (j / 10) * (j % 10) == i)
++ans;
std::cout << ans << std::endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
bool visited[100005];
bool arr[100005];
int dp[100005];
int parent[26];
int find(int x) {
if (parent[x] == -1) {
return x;
}
return find(parent[x]);
}
int main() {
int n;
cin >> n;
int indegree[n], xo[n];
queue<int> q;
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += (s[i] == 'B');
}
vector<int> A;
if (sum % 2 == 0) {
for (int i = 0; i < n - 1; i++) {
if (s[... | 2 |
#include <bits/stdc++.h>
template <class _Tp = int>
_Tp read() {
_Tp w = 0;
bool f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) w = (w << 3) + (w << 1) + (ch ^ 48), ch = getchar();
return f ? -w : w;
}
const int kMaxN = 5e2 + 5;
int n, m;
std::bitset<kMa... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> p[100005];
long long cnt[100005];
int pre[30000005];
int size[30000005];
int lst[100005];
int y[100005];
int main() {
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d %d", &p[i].first, &p[i].second);
y[i] = p[i].second;
... | 4 |
#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
using namespace std;
int n;
int k;
int m;
map<long long, vector<int> > M;
long long a[500500], b[500500], c[500500], P[500500];
long long mod = 1000 * 1000 * 1000 + 7;
int p[500500];
long long ans = 0;
int SZ;
void clr(int x) { p[... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e6) + 100;
struct LINK {
int id, next;
};
int n, now;
int h[maxn];
int f[maxn], ans[maxn];
bool vis[maxn];
LINK t[maxn * 2];
vector<int> deep[maxn];
void join(int u, int v) {
t[now].id = v;
t[now].next = h[u];
h[u] = now++;
t[now].id = u;
t... | 6 |
#include <bits/stdc++.h>
using namespace std;
int p[10000001];
int fa[10000001], fb[10000001];
int a[100005], b[100005];
void gao(int n, int x[], int g[]) {
for (int i = 0; i < n; ++i) {
scanf("%d", &x[i]);
for (int y = x[i]; y > 1; y /= p[y]) ++g[p[y]];
}
}
void output(int x[], int n, int f[]) {
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace minmax {
template <class T>
T max(T&& A) {
return A;
}
template <class T>
T min(T&& A) {
return A;
}
template <class T>
T max(T&& A, T&& B) {
return A > B ? A : B;
}
template <class T>
T min(T&& A, T&& B) {
return A < B ? A : B;
}
template <class T, class.... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long *fac, *ifac;
long long powmod(long long b, long long e, long long mod) {
long long res = 1;
while (e > 0) {
if (e % 2 == 1) res = (res * b) % mod;
e = e / 2;
b = (b * b) % mod;
}
return (res % mod);
}
long long in... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, ans;
int main() {
cin >> a >> b;
if (a == b) {
cout << "infinity";
return 0;
}
if (a < b) {
cout << "0";
return 0;
}
for (int i = 1; i * i <= a - b; i++)
if ((a - b) % i == 0) {
if (i > b) ans++;
if ((a - b) / i > ... | 2 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
struct SegmentTree1 {
int siz;
vector<long long> tree;
long long def = -2001001001;
SegmentTree1(int temp) {
siz = temp;
for (int i = 0; i < siz * 2; i++) tree.push_back(def);
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, m;
cin >> n >> m;
unsigned long long a[101] = {0};
for (unsigned long long i = 0; i < m; i++) {
unsigned long long k, f;
cin >> k >> f;
a[k] = f;
}
unsigned long long ans = 0;
for (unsigned long long i = 1; i <= 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int al, bl, ar, br;
cin >> al >> ar >> bl >> br;
if (br >= (al - 1) && ((al + 1) * 2) >= br) {
cout << "YES";
return 0;
}
if (bl >= (ar - 1) && ((ar + 1) * 2) >= bl) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
int main() {
int r;
int summ = 0;
int n;
std::cin >> n;
for (int i = 0; i < n; ++i) {
std::cin >> r;
summ += r;
}
std::cout << summ / n << std::endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[100000];
gets(a);
int len = strlen(a);
string s;
for (int i = 0; i < len; i++) {
if (a[i] != ' ') s += tolower(a[i]);
}
int si = s.size();
if (s[si - 2] == 'a' || s[si - 2] == 'e' || s[si - 2] == 'i' ||
s[si - 2] == 'o' || s[si ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
pair<long long, long long> tree[4 * N];
long long a[N], dp[N];
void build(int node, int s, int e) {
if (s == e) {
tree[node] = {a[s], s};
return;
}
int md = (s + e) >> 1;
build(node << 1, s, md);
build((node << 1) + 1, md + 1, e);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2 != 0) {
cout << (n + 1) / 2 << endl;
} else if (n % 2 == 0 && n != 0) {
cout << n + 1 << endl;
} else if (n == 0)
cout << "0" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x = 0;
int y = 0;
int z = 0;
for (int i = 0; i < n; i++) {
int t_x;
int t_y;
int t_z;
cin >> t_x;
cin >> t_y;
cin >> t_z;
x += t_x;
y += t_y;
z += t_z;
}
if (x == 0) {
if (y == 0) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, inf = 10e9;
int H, W, nh, nw, m = 0;cin >> H >> W;
P p;
vector<string> v(H);
vector<vector<int>> d(H, vector<int>(W));... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define inf 1000000007
#define int long long
signed main() {
int n;
cin >> n;
vector<pair<int, int>> v;
rep(i, n) {
int a, b;
cin >> a >> b;
v.push_back(make_pair(a, 1));
v.push_back(make_pair(b + 1, -1));
}
sort(v... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long c, d;
if (b == 1) {
return a % 1000000007;
} else if (b % 2 == 0) {
c = power(a, b / 2);
return (c * c) % 1000000007;
} else {
c = power(a, b / 2);
d = (c * c) % 1000000007;
d = (d * a) % ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, rep[2000009];
long long cur, ans;
bool is[2000009];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
rep[x]++;
is[x] = 1;
}
for (int i = 200000; i >= 0; i--) rep[i] += rep[i + 1];
for (int i = 1; i <=... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 1031;
int n, m, k;
int board[N][N];
int si, sj;
int dist[N][N], used[N][N];
bool outside(int a, int b) { return (a < 1 || a > n || b < 1 || b > m); }
bool valid_move(int a, int b, int D) {
if (outside(a, b)) re... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
if (b > a)
cout << "-1" << endl;
else if (a % b == 0 && (a / b) % 2 == 1)
cout << b << endl;
else {
int temp = (a - b) / (b * 2) * 2 + 1;
double ans = (double)(a + b) / (temp + 1);
printf("%.10lf\n", ans);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int b[1000005];
int main() {
ios::sync_with_stdio(false);
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) b[a[i]] = 1;
int sum = 0, result = 0, len = 0;
for (int i = 0; i < 1000005; i++)... | 4 |
#include <bits/stdc++.h>
int main(void) {
char str[30], c = ' ', field[2][13];
fgets(str, 30, stdin);
int i = 1, i2, j2, l;
while (str[i]) {
if (c == ' ') {
for (int j = 0; j < i; j++) {
if (str[i] == str[j]) {
c = str[j];
l = i - j - 1;
i2 = j;
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 100;
const int maxm = 2000000 + 100;
const int maxt = 3000000 + 100;
const int maxk = 10 + 3;
const long long unit = 1LL;
const int INF = 0x3f3f3f3f;
const long long Inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-3;
const double inf = 1e15;
cons... | 5 |
#include <bits/stdc++.h>
const int MOD = 998244353;
int binPow(int a, int n) {
int res = 1;
while (n) {
if (n & 1) res = (1LL * res * a) % MOD;
a = (1LL * a * a) % MOD;
n >>= 1;
}
return res;
}
using namespace std;
long long int fact(long long num) {
long long res = 1;
for (int i = 1; i <= num; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int n, x;
void Fun(int l, int r, int& c) {
if (l >= n) return;
int t = ceil(1.0 * x / vec[l]);
if (r - t + 1 >= l) {
++c;
Fun(l + 1, r - t + 1, c);
}
return;
}
void Solve() {
cin >> n >> x;
vec.resize(n);
for (auto& el : vec) cin >> ... | 3 |
#include <iostream>
using namespace std;
int main() {
int n, q;
while (cin >> n >> q) {
if (n == 0 && q == 0) {
break;
}
int hyou[101] = {0};
for (int i = 0; i < n; i++) {
int k;
cin >> k;
for (int j = 0; j < k; j++) {
int a;
cin >> a;
hyou[a]++;
}
}
int max = 0;
int data = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> tu[120];
long long dp[120][70], zs[120], biaoji[120];
long long n, k;
long long mod = 1e9 + 7;
void dfs(int gen) {
if (biaoji[gen]) return;
biaoji[gen] = 1;
dp[gen][0] = dp[gen][k + 1] = 1;
for (int a = 0; a < tu[gen].size(); a++) {
if (biaoji[tu[gen... | 3 |
#include <bits/stdc++.h>
template <class T>
T min(T x, T y) {
return x < y ? x : y;
}
int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a, b;
int data[1001] = {0};
int find(int n) {
int parent = n;
vector<int> compress;
while (data[parent] != parent) {
compress.push_back(parent);
parent = data[parent];
}
for (auto i : compress) data[i] = parent;
return parent;
}
int main() ... | 3 |
#include<iostream>
#include <string>
using namespace std;
int weak(string& s, int& i);
int strong(string& s, int& i);
int fc(string& s, int& i);
int inte(string& s, int& i);
int weak(string& s, int& i) {
int buf = strong(s, i);
while (s[i] == '+' || s[i] == '-') {
if (s[i] == '+') {
i++;
buf += strong(s, i)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
n = n % 4;
if (n == 0 || n == 3)
cout << "0" << endl;
else if (n == 1)
cout << "1" << endl;
else if (n == 2)
cout << "1" << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
point(long long _x, long long _y) {
x = _x;
y = _y;
}
point() {}
};
struct cmp {
bool operator()(point a, point b) { return (a.x < b.x); }
};
struct vec {
long long x, y;
vec(long long _x, long long _y) {
x = _x;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& cout, pair<T1, T2>& p) {
cout << p.first << "\t" << p.second << "\n";
return cout;
}
template <class T>
istream& operator>>(istream& cin, vector<T>& arr) {
for (long long i = 0; i < arr.size(); i++) cin >> arr... | 3 |
#include <bits/stdc++.h>
int num[1024];
int main() {
int k;
int n;
int temp;
scanf("%d", &k);
while (k--) {
memset(num, 0, sizeof(int) * 1024);
scanf("%d", &n);
int i;
int max = 1;
for (i = 0; i < n; ++i) {
scanf("%d", &temp);
int j;
for (j = 1; j <= temp; ++j) ++num[j];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int T, N, K, L, t, d, a;
int main() {
cin >> T;
while (T--) {
a = t = 0;
cin >> N >> K >> L;
while (N--) {
cin >> d;
d -= L;
t *= d > -K;
t = std::max(t, K + d);
a |= d + t++ > K;
}
if (a)
cout << "No" << endl;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int mov[256][2];
int c[111][2];
int a, b, n, i, x;
char s[111];
int f(int a, int b) {
if (a != 0)
return b / a;
else
return 0;
}
int main() {
mov['U'][0] = 0;
mov['U'][1] = 1;
mov['D'][0] = 0;
mov['D'][1] = -1;
mov['L'][0] = -1;
mov['L'][1] = 0;
mo... | 1 |
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int d;
scanf("%d", &d);
int c[26];
int s[365][26];
int t[365];
for (int i = 0; i < 26; i++) {
scanf("%d", &c[i]);
}
for (int i = 0; i < d; i++) {
for (int j = 0; j < 26; j++) {
scanf("%d", &s[i][j]);
}
}
for (int i = 0; i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const long long MOD = 1e9 + 7;
int n, m, k, z[2 * N], match[2][N + 1];
char tmp[N];
string s, t;
int main() {
scanf("%d%d%d", &n, &m, &k);
scanf("%s", tmp);
s = string(tmp);
scanf("%s", tmp);
t = string(tmp);
memset(match, -1, sizeof match)... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
if (a < 0) return gcd(-a, b);
if (b < 0) return gcd(a, -b);
return (b == 0) ? a : gcd(b, a % b);
}
template <class T>
inline T lcm(T a, T b) {
if (a < 0) return lcm(-a, b);
if (b < 0) return lcm(a, -b);
return a * (b /... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m, k;
cin >> n >> m >> k;
long long w, x, y;
vector<pair<long long, long long>> v[n + 1];
map<pair<long long, long long>, long long> mapp;
for (long long i = 0; i < m; i++) {
cin ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int L_N = 1e6 + 10;
int N, M;
const int INF = 1e8;
struct node {
int l_mi, l_mx;
int r_mi, r_mx;
int l, r;
node() { l_mi = r_mi = INF; }
} t[L_N];
void cant() {
printf("IMPOSSIBLE\n");
exit(0);
}
int st[L_N][22];
int rmq(int l, int r) {
if (l > r) return... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int l, a, b, m;
cin >> l >> a >> b >> m;
vector<long long int> pow10(19, 1);// pow10[i] = 10^i
for(int i=0; i+1<19; i++) pow10[i+1] = pow10[i] * 10;
vector<vector<long long int>> base_matrix(3, vector<long long int>(3));
base... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e6 + 87;
const ll MOD = 1e9 + 7;
ll f[N], fi[N];
ll c(ll n, ll k)
{
return f[n] * fi[k] % MOD * fi[n - k] % MOD;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
f[0] = f[1] = fi[1] = fi[0] = 1;
for (int i = 2; i < N... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MINF = 0x80000000;
const long long mod = 1000000007;
const int cons = 60;
const int b16 = 1 << 16;
int s[cons];
int prime[16] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
int ans[101];
int xt[101][b16];
int yt[101][b1... | 2 |
#include <bits/stdc++.h>
const int N = 2e5 + 10;
long long dp[N];
int a[N];
long long sum[N];
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum[i] += sum[i - 1] + a[i];
}
long long maxn = sum[n];
for (int i = n - 1; i >= 1; i--) {
dp[i] = maxn;
maxn = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const long long INF = 1e18;
const long long magic = 100000;
vector<int> cycle;
vector<set<int>> g;
vector<int> used;
void euler_cycle(int v) {
used[v] = 1;
stack<int> s;
s.push(v);
while (!s.empty()) {
int v = s.top();
if (g[v].empty())... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int r,c;
while(1){
cin>>r>>c;
if(r==0) return 0;
int senbei[r][c];
for(int i=0;i<r;i++){
for(int j=0;j<c;j++) cin>>senbei[i][j];
}
int ans=0;
bool temp[r][c];
for(int t=0;t<(1<<r);t++){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
... | 0 |
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){
int n;
long long int a[100000];
int count = 0;
map<long int, int> m;
cin >> n;
for(int i = 0;i < n;i++){
cin >> a[i];
m[a[i]] = i;
}
sort(a, a + n);
for(int i = 0;i < n;i++){
if((m[a[i]] - i) % 2){
count++;
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int chel[100005];
pair<int, int> min1[530], min2[530];
pair<int, pair<int, int> > summa[530];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int kol;
cin >> kol;
for (int j = 1; j <= kol; ... | 6 |
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
void func(int d, vector<int>&v) {
for (int i = 1; i*i <= d; i++) {
if (d%i == 0)v.push_back(i);
}
}
int main() {
int a, b;
while (scanf("%d%d", &a, &b), a) {
vector<int>u, v;
func(a, u); func(b, v);
int Min = INT_MAX;
for (... | 0 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
while(cin>>n>>m,n){
vector<ll> s(n),d(m+1)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
double l, v1, v2;
double binser(double target) { return target / (v1 + v2); }
double msafa;
double solve(double start, double End, int students) {
if (start >= End) {
msafa = End;
return 0;
}
if (students == 0) {
msafa = min(start + 0.0001, End);... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, a, b;
cin >> n >> s;
int ans = s;
for (int i = 0; i < n; i++) {
cin >> a >> b;
ans = max(ans, (a + b));
}
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
double pi = 3.14159265;
long long n;
vector<vector<long long> > g;
vector<int> c;
long long rt;
vector<long long> ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
g.resize(n + 1);
c.resize(n + 1);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10], t[10];
for (int i = 0; i < 4; ++i) {
scanf(" %c", &s[i]);
}
for (int j = 0; j < 4; ++j) {
scanf(" %c", &t[j]);
}
swap(s[2], s[3]);
swap(t[2], t[3]);
for (int i = 0, j = 0; i < 4; ++i) {
if (s[i] != 'X') {
s[j++] = s... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solution() {
string s;
cin >> s;
s[0] = toupper(s[0]);
cout << s << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T = 1;
for (int t = 0; t < T; t++) {
solution();
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const int N = 100010;
int h[N];
int main() {
int n;
scanf("%d", &n);
int i, j;
for (int k = n - 1; k--; scanf("%d%d", &i, &j), h[i - 1]++, h[j - 1]++)
;
int f = 1;
for (int i = 0; i < n; f &= h[i] != 2, i++)
;
... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
double r;
cin>>r;
printf("%.7f %.7f\n",r*r*M_PI,2*r*M_PI);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char cad1[100];
char cad2[100];
int cd = 0;
scanf("%s %s", &cad1, &cad2);
for (int i = 0; i < strlen(cad1); ++i) {
if (cad1[strlen(cad1) - 1] != '*') {
for (int j = 0; j < strlen(cad2); ++j) {
if (cad1[i] == cad2[j]) {
cad1... | 1 |
#include<cstdio>
using namespace std;
int n;
int a[20010],b[20010],p[20010];
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d",&p[i]);
for (int i=1;i<=n;i++)
{
a[i]=i*(n+1);
b[i]=(n-i+1)*(n+1);
}
for (int i=1;i<=n;i++)
b[p[i]]-=(n-i+1);
for (int i=1;i<=n;i++)
printf("%d%c",a[i]," \n"[i==n... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long cnt(long long l, long long r, vector<vector<long long> > &dp,
vector<long long> &a, vector<vector<long long> > &fval) {
if (l == r) {
return a[l];
}
if (dp[l][r] != -1) return dp[l][r];
long long lft = cnt(l + 1, r, dp, a, fval);
long l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int T;
map<string, int> M;
char comando[1024];
char tipo[1024], nome[1024];
int asteriscos(char *s) {
int c = 0, n = strlen(s);
for (int i = 0; i < n; i++)
if (s[i] == '*') c++;
return c;
}
int Es(char *s) {
int c = 0, n = strlen(s);
for (int i = 0; i < n; i++... | 2 |
#include<bits/stdc++.h>
using namespace std;
int i,j,a[20],n,b,c;
int main()
{
for(cin>>n;i<n;i++)cin>>a[i];
for(i=1;i<n-1;i++)if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1]))c++;
cout<<c;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
vector<string> w={"SUN","MON","TUE","WED","THU","FRI","SAT"};
for(int d=0;d<7;d++)
if(s==w.at(d))
cout<<7-d<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1 = 0, x2 = 0, x3 = 0;
cin >> x1 >> x2 >> x3;
int ans = abs(x2 - x1) + abs(x3 - x1);
if (abs(x1 - x2) + abs(x3 - x2) < ans) {
ans = abs(x1 - x2) + abs(x3 - x2);
}
if (abs(x1 - x3) + abs(x2 - x3) < ans) {
ans = abs(x1 - x3) + abs(x2 - x3... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
struct Max {
vector<int> d;
int n;
void Init(int n) {
this->n = n;
d.resize(n * 2, 0);
}
void Set(int p, int v) {
p += n;
d[p] = max(d[p], v);
for (p >>= 1; p > 0; p >>= 1) {
d[p] = max(d[p * 2],... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
set<string> store;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
store.insert(s[i]);
}
vector<string> left, right;
string mid;
for (int i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
vector<int> g[n + 1];
for (int i = 0; i < n; i++) {
cin >> x;
g[i + 1].push_back(x);
}
long long dp[n + 1][n + 1], mod = 1000000007;
for (int i = 1; i < n + 1; i++) {
for (int j = i; j < i + 2; j++) {
if (i ==... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool pairCompare1(const std::pair<string, int>& firstElem,
const std::pair<string, int>& secondElem) {
return firstElem.second > secondElem.second;
}
bool pairCompare2(const std::pair<int, int>& firstElem,
const std::pair<int, int>& sec... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &a) {
a = 0;
int c = getchar(), b = 1;
while (c > '9' || c < '0') {
if (c == '-') b = -1;
c = getchar();
}
while (c >= '0' && c <= '9') a = (a << 3) + (a << 1) + c - 48, c = getchar();
a *= b;
}
inline void write(int x) {
if (x > 9... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
long long l, r, q;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> q;
while (q--) {
cin >> l >> r;
long long ans = l;
for (long long i = 0; i <= 63; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long mpe(long long base, long long exponent, long long modulus) {
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) result = result * base % modulus;
exponent = exponent >> 1;
base = base * base % modulus;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int main() {
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int x = a & b;
cout << (a ^ x) + (b ^ x) << "\n";
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 7;
long long modpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return ans;
}
int n, Q;
long long p[N], q[N], cp[N];
comple... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int f[3][4] = {
{0, 1, 2, 3},
{0, 2, 3, 1},
{0, 3, 1, 2},
};
int64_t g(int64_t n) {
int cat = (n % 3 - 1 + 3) % 3;
int basei;
for (basei = 0; (1LL << basei) <= n; basei += 2)
;
basei -= 2;
n = (n - (1LL << basei)) / 3;
vector<int> a;
whil... | 5 |
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <nume... | 0 |
#include <iostream>
#include <string>
#define int long long
#define INF 1e+17
using namespace std;
int n;
int C(int x){
if(x == 1) return 1;
int tmp = 1,ret = 0,keta = 1;
while(tmp <= x){
int three = min(tmp * 10,x) / 3 - tmp / 3,five = min(tmp * 10 - 1,x) / 5 - (tmp - 1) / 5;
int tf = min(tmp * 10 - 1,x) / 15... | 0 |
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int N;
vector<int> P,Pd;
int main()
{
cin >> N;
P = vector<int>(N + 1);
Pd = vector<int>(N + 1);
for (int i = 1;i<=N;i++) {
cin >> P[i];
Pd[P[i]] =i;
}
long long ans = 0;
multiset<int> s;
s.insert(0);
s.insert(0);
s.insert(... | 0 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cassert>
#include<iomanip>
#include<cstdio>
#include<cassert>
#include<queue>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define MA... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int max(const int &a, const int &b) { return a > b ? a : b; }
const int N = 2000 + 13;
int n, k, f[N];
inline void solve() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) f[i] = -1;
f[0] = 0;
for (int i = 1, x; i <= n; ++i) {
scanf("%d", &x);
fo... | 5 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
vector<int> get_leq(int k, bool eq = true) {
vector<int> res;
if (eq) res.emplace_back(k);
while (k) res.emplace_back(k - 1), k -= k & -k;
return res;
}
int main() {
int n, k; cin >> n >> k;
vector<int> a(n), b(n);... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > vv;
int n, m, h, t;
vector<pair<int, int> > edges;
vector<int> add;
int count(int v1, int v2) {
int ans = 0;
vector<int> all;
int id1 = 0, id2 = 0;
while (id1 < vv[v1].size() || id2 < vv[v2].size()) {
if (id1 == vv[v1].size()) {
all.pu... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int A[1000001], temp;
int main() {
int N, t;
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%d", A + i);
}
cin >> t;
for (int i = 0; i < t; i++) {
cin >> temp;
A[temp - 1] *= -1;
}
stack<long long int> negative;
for (int i = N - 1; i ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.