solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct pairvar {
int a;
int b;
};
bool isPrime(long long x) {
if (x == 1) {
return false;
}
long long a = (long long)x;
for (int i = 2; i <= (long long)sqrt((double)a); i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
int gcd(int a... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, s;
scanf("%d", &n);
map<int, int> mp;
for (int i = 0; i < n; i++) {
scanf("%d", &a);
mp[a]++;
}
scanf("%d", &m);
int b[m], Max1 = 0, Max2 = 0, idx = 1;
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
}
for (int i =... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long sum[2][200005];
void add(bool f, int x, int n, long long val) {
while (x <= n) {
sum[f][x] += val;
x += (x & -x);
}
return;
}
long long query(bool f, int x) {
long long ret = 0;
while (x) {
ret += sum[f][x];
x -= (x & -x);
}
return re... | 9 |
#include <bits/stdc++.h>
using namespace std;
int hole[1000002];
int bone[1000002];
int main() {
int result = 1;
bone[1] = 1;
int n, m, K;
cin >> n >> m >> K;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
hole[x] = 1;
}
if (hole[1] == 1) {
cout << "1";
return 0;
}
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int cmp(int a,int b){
return a>b;
}
signed main(){
ios::sync_with_stdio(false);
// freopen("input.txt","r",stdin);
int t,n,m;
cin>>t;
while(t--){
cin>>n>>m;
vector<int> k(n+1);
vector<int> c(m+1);
for(int i=1;i<=n;i++){
cin>>k[i];
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 4105;
int N;
long long Cost[SZ];
long long sum;
long long res = (long long)1e15;
int main() {
int i, j, k;
scanf("%d", &N);
for (i = 1, j = 0; i <= N + N; i++) {
double x;
scanf("%lf", &x);
Cost[i] = (long long)(1000.0 * x + .5) % 1000ll;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int MIN(long long int a, long long int b) { return (a < b) ? a : b; }
long long int MAX(long long int a, long long int b) { return (a > b) ? a : b; }
long long int ABS(long long int x) { return (x > 0) ? x : -x; }
int MIN(int a, int b) { return (a < b) ? a : b; }
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[100000], i, n, temp = 0, c = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
if (a[i] > 0) {
temp = temp + a[i];
}
if (a[i] == -1 && temp != 0) {
temp--;
} else if (temp == 0)
... | 0 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
int spf[100001];
using namespace std;
void primeFactors(long long n, vector<long long> &vec) {
while (n % 2 == 0) {
vec.push_back(2);
n = n / 2;
}
for (long long i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
vec.push_back(i);
n = n... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
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;
}
long long gcd(long long a, long long b) { re... | 20 |
#include <bits/stdc++.h>
int a[1212][1212];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int all_s = 0;
bool is_gone[1212][1212][4];
int ans = 0;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void dfs(int x, int y, int dir, int go) {
int i;
bool f = 0;
for (i = 0; i < 4; i++) {
if (is_... | 15 |
#include <bits/stdc++.h>
using namespace std;
int fa[10110];
int find(int x) {
if (x != fa[x]) fa[x] = find(fa[x]);
return fa[x];
}
void merge(int x, int y) {
int fx = find(x);
int fy = find(y);
if (fx != fy) {
if (fx > fy)
fa[fx] = fy;
else
fa[fy] = fx;
}
}
int main() {
int n, m;
sc... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2010;
const int MOD = 1000000007;
int n, m;
long long F[MaxN][MaxN], sF[MaxN][MaxN], tF[MaxN][MaxN], a[MaxN][MaxN],
b[MaxN][MaxN], c[MaxN][MaxN], d[MaxN][MaxN];
long long ans;
int main() {
cin >> n >> m;
for (int i = 1; i < m; ++i) {
F[1][i] = 1... | 16 |
#include <bits/stdc++.h>
int main() {
int n, m, i;
long long ans, now;
scanf("%d%d", &n, &m);
ans = 2 * m, now = m;
for (i = 2; i <= n; i++)
ans = (ans * (2 * m - 1) + now) % 1000000007, now = now * m % 1000000007;
printf("%lld\n", ans);
return 0;
}
| 15 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> seive() {
long long n = 2;
vector<long long> pr(200000, -1);
for (int i = n; i < 200000; i++) {
if (pr[i] == -1)
pr[i] = 1;
else
continue;
for (int j = 2 * i; j < 200000; j += i) pr[j] = 0;
}
return pr;
}
long long powmod(... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<vector<int> > v;
vector<int> cc;
int n, m, i, j, k, temp, zc = 0;
int vis[200];
int flag = 0;
int ans = 0;
for (i = 0; i < 200; i++) vis[i] = 0;
queue<int> qu;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) v.push_back(cc);
for (i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007LL;
long long large = 2000000000000000000LL;
int n, q;
vector<vector<pair<int, long long> > > adj;
vector<long long> lv;
vector<long long> pre;
vector<long long> maxi;
vector<int> pa;
void dfs(int u, int parent, long long dep) {
pa[u] = parent;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, a[N], vis[N], ans;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++)
if (!vis[a[i]]) {
ans++;
for (int j = 1; a[i] * j <= 100... | 0 |
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
int x=0;
bool flag=1;
char c=getchar();
while(c<'0'||c>'9')
{
if(c=='-')
flag=0;
c=getchar();
}
while(c>='0'&&c<='9')
{
x=(x<<1)+(x<<3)+c-'0';
c=getchar();
}
return (flag?x:~(x-1));
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, pa, pb;
cin >> n;
vector<int> a(n), ans(n);
for (i = 0; i < n; i++) cin >> a[i];
bool solved = true;
pa = -1;
pb = 10000000;
ans[0] = 0;
for (i = 0; i < n; i++) {
if ((a[i] <= pa... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b;
cin >> n >> b;
vector<int> cost(n), lim(n), bonus(n);
for (int i = 0; i < n; i++) {
cin >> cost[i];
lim[i] = cost[i] / 2;
}
auto valid = [&]() {
int x = b;
for (int i = 0; i < n; i++) {
if (bonus[i] > x) {
ret... | 23 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long logPow(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) {
ans *= a;
}
a *= a;
b = b >> 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int num[200005];
void solve();
bool ifMod(int);
int n, result, max_num;
int show[1000006];
int main() {
scanf("%d", &n);
result = 0;
max_num = 0;
memset(num, 0, sizeof(num));
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
max_num = max(max_num, num[i]... | 13 |
#include <bits/stdc++.h>
struct container {
int id;
int boxes;
int matches;
} c[21], tmp;
int n, m, total;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d %d", &c[i].boxes, &c[i].matches);
c[i].id = i;
}
for (int i = 1; i < m; i++)
for (int j = 1; j < m; j++)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200000 + 5;
pair<int, int> a[maxN];
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
map<pair<int, int>, int> point;
map<int, int> x;
map<int, int> y;
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
x[a[i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, s;
long long ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
ans += s * i;
}
cout << ans;
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n;
set<int> all;
struct d {
map<int, int> v;
int& operator[](int x) { return v[x]; }
void init(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) {
int cnt = 0;
while (x % i == 0) cnt++, x /= i;
v[i... | 24 |
#include <bits/stdc++.h>
template <class T>
inline void chkmax(T &x, const T &y) {
if (x < y) x = y;
}
template <class T>
inline void chkmin(T &x, const T &y) {
if (x > y) x = y;
}
template <class T>
inline void read(T &x) {
char c;
int f = 1;
x = 0;
while (((c = getchar()) < '0' || c > '9') && c != '-')
... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (a < b) a = b;
}
const int oo = 1 << 30;
const double eps = 1e-7;
const int N = 1;
const int M = 1;
const long long P = 10000000097ll;
map<lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 5];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int c[n + 5];
for (int i = 0; i < n; i++) {
c[i] = 0;
}
int p = 0;
for (int i = 1; i < n; i++) {
if (a[i] != a[i - 1]) {
c[p]++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void debug() { cout << endl; }
template <class T, class... U>
void debug(T a, U... b) {
cout << a << " ";
debug(b...);
}
template <class T>
void pary(T l, T r) {
while (l != r) {
cout << *l << " ";
l++;
}
cout << endl;
}
int par[2 * 200005], siz[2 * 200005... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long a[1001][1001], b[1001] = {0}, c[1001] = {0}, d[1000001], e[1000001];
int main() {
ifstream inf("input.txt");
long long n, m, k, p;
cin >> n >> m >> k >> p;
for (int i = 1; i <= n; i++)
for (int i1 = 1; i1 <= m; i1++) cin >> a[i][i1];
for (int i = 1; ... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int res = 0, c, d = 0;
while (c = getchar(), c < '0' || c > '9')
;
do {
res = (res << 3) + (res << 1) + (c ^ 48);
} while (c = getchar(), c >= '0' && c <= '9');
return res;
}
const int maxn = 300010;
vector<int> edge[maxn];
sta... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, a, b;
cin >> x >> y >> a >> b;
int n = y - x;
if (n < 0) {
n = -n;
swap(a, b);
a = -a;
b = -b;
}
if (n < a) {
cout << "DRAW"
<< "\n";
return 0;
}
if (n >= a && n <= b) {
cout << "FIRST"
<< ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) { return a == 0 ? b : GCD(b % a, a); }
string ntoa(int b) {
string a = "";
while (b) {
a += (b % 10 + '0');
b /= 10;
}
reverse(a.begin(), a.end());
return a;
}
struct cake {
int h;
int w;
cake(int a, int b) {
h = a;
w = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
long long dp[maxn], pre[maxn], book[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> book[i];
sort(book + 1, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m = 0;
cin >> n;
int ar[n];
for (int i = 0; i < n; i++) cin >> ar[i];
for (int i = 0; i < n - 1; i++) {
if (ar[i] != ar[n - 1]) {
m = max(m, n - i - 1);
break;
}
}
for (int i = n - 1; i >= 1; i--) {
if (ar[i] != ar[0... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long const mod = 1000000007;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
inline long long add(long long a, long ... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class graph {
public:
struct edge {
int from;
int to;
T cost;
};
std::vector<edge> edges;
std::vector<std::vector<int>> g;
int n;
graph(int _n) : n(_n) { g.resize(n); }
virtual int add(int from, int to, T cost) = 0;
};
templa... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int buffer_size = 1e5 + 5;
char buf[buffer_size], *S, *T;
bool flag_EOF;
inline char read_char() {
if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin);
return S != T ? *(S++) : EOF;
}
inline int read_int() {
bool flag = false;
char c = read_char();
... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long a, b;
int xx[1000000], yy[1000000], n, m, ans, bo[100000];
int check(int p, int x, int y) {
if ((!p) || (!(x + y))) return 1;
int l, r;
if (x)
l = xx[p];
else
l = 0;
if (y)
r = yy[p];
else
r = 9;
for (int i = l; i <= r; i++)
if (b... | 19 |
#include <bits/stdc++.h>
using namespace std;
char S[210000];
int n, col[210000];
vector<int> V[8];
int disp[8][210000], disc[8][8];
queue<int> q;
int f[8][1 << 8];
long long ans[24];
int main() {
scanf("%d", &n);
scanf("%s", S);
for (int i = 0; i < n; i++) col[i + 1] = S[i] - 'a';
for (int i = 1; i <= n; i++) ... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long pow1(long long a, long long b, long long mod) {
if (b == 0) return 1;
long long ret = pow1(a, b / 2, mod);
ret = (ret * ret) % mod;
if (b & 1) ret = (a * ret) % mod;
return ret;
}
int main() {
int n;
scanf("%d", &n);
printf("%lld\n",
(pow1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const long long linf = (1ll << 62) - 1;
int main() {
int n;
cin >> n;
vector<int> is_prime(n + 1, true), primes;
is_prime[0] = is_prime[1] = 0;
for (int i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (int j = i * i; j <= ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e6 + 3;
const double EPS = 1e-10;
const double pi = 3.14159265358979323846;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int frq[27];
int main() {
fast();
int n;
cin >> n;
int* arr = new int[n];
for (int i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
deque<string> names;
multiset<string> above;
int state = 0;
int name_start = 0, len, ans = 0;
string str, cur_name;
cin >> str;
for (int i = 0; i < str.size(); ++i) {
switch (state) {
case 0:
if (str[i] == ':') {
len = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
long long int temp;
cin >> n >> k;
temp = n / 2;
if (n % 2) temp++;
if (k <= temp)
cout << (1 + (k - 1) * 2);
else
cout << (2 + (k - temp - 1) * 2);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long st1 = 0, st2 = 1, st3 = 2;
vector<long long> g(n);
for (int i = 0; i < n; ++i) {
cin >> g[i];
}
while (st3 < n && g[st3] - g[st1] > m) {
st3++;
st1++;
st2++;
}
if (st3 == n) {
cout <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int f[1000050], t[1000050], x, k, kq[1000050];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (long long i = 2; i <= 1e6; i++)
if (f[i] == 0) {
for (long long j = i * i; j <= 1e6; j += i) f[j] = 1;
t[i] = t[i - 1] + 1;
} ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
long long n, k;
while (t--) {
long long cnt = 0;
scanf("%lld%lld", &n, &k);
while (n) {
if (n % k == 0)
n /= k, cnt++;
else
cnt += n % k, n -= n % k;
}
printf("%lld\n", cnt);
}
return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m;
vector<int> edge[N][2];
int ch[N][2];
bool flag = true;
int go(int l, int r) {
int nxt = l + 1, bar = l;
for (int i = 0; i < (int)edge[l][0].size(); ++i) {
bar = max(bar, edge[l][0][i]);
if (edge[l][0][i] <= l) {
flag = fal... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000009;
long long a = 2, b = 2, c = 4, n;
int main() {
scanf("%I64d", &n);
a = 2, b = 2, c = 4;
while (n -= 2) {
a = a * 2 % mod, c = c * (a - 3) % mod, b = (b + c) % mod;
}
printf("%I64d\n", (b * b + 1) * 2 % mod);
return 0;
}
| 18 |
#include <bits/stdc++.h>
using namespace std;
int n, cev[1505];
long long int m;
int main() {
scanf("%d %lld", &n, &m);
int a = 1, b = n;
for (int i = n; i > 1; i--)
if (m <= (1ll) << (i - 2)) {
cev[a] = n - i + 1;
a++;
} else {
m -= (1ll) << (i - 2);
cev[b] = n - i + 1;
b--;... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return (out);
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
int l = v.size();
for (int i = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2.5e5 + 5;
long long fact[N], ans[N];
long long sub(long long a, long long b, long long mod) {
if (a - b < 0) return a - b + mod;
return a - b;
}
long long add(long long a, long long b, long long mod) {
if (a + b >= mod) return a + b - mod;
return a + ... | 8 |
#include <bits/stdc++.h>
using namespace std;
char string_in_buffer[(int)260];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a;
if (m > n) {
a = m;
m = n;
n = a;
}
cout << n - 1 << " " << m << endl;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[1010], b[1010], c[1010], d[1010], ra[1010], rb[1010], rc[1010],
rd[1010];
struct node {
long long x, y, p, q;
};
deque<node> ans;
inline long long read() {
long long x = 0, tmp = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') tm... | 21 |
#include <bits/stdc++.h>
using namespace std;
int rect1x1, rect1y1, rect1x2, rect1y2;
int rect2x1, rect2y1, rect2x2, rect2y2;
int n;
int test(int a, int b, int c, int d) {
cout << "? " << a << " " << b << " " << c << " " << d << "\n";
cout.flush();
int ret;
cin >> ret;
if (rect1x1 >= a and rect1y1 >= b and re... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INT_INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int POS[8] = {0, 1, 0, -1, 1, 0, 1, -1};
const int MAXM = 1000005;
const int MAXN = 100005;
const int W = 0;
const int B = 1;
long long count(int x1, int y1, int x2, ... | 7 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int t;cin>>t;
while(t--)
{
ll x;cin>>x;
ll y;cin>>y;
ll sum=0;
for(ll k=1;k*k<x;k++)
{
sum+=max(0LL,(min(y,(x/k)-1))-k);
}
cout<<sum<<'\n';
}
} | 9 |
#include <bits/stdc++.h>
int d[1000011], a, b, n, m;
int main() {
memset(d, 0, sizeof(d));
scanf("%d%d", &n, &m);
long long r = n * (n - 1ll) * (n - 2) / 6;
while (m--) {
scanf("%d%d", &a, &b);
r -= n - (++d[a]) - (++d[b]);
}
printf("%I64d\n", r);
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
struct TRes {
int mina;
int gmx, lmx, rmx, smx;
TRes operator+(TRes r) const {
if (mina < r.mina)
... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, dd, uui;
cin >> n >> k;
char a[343][345];
if (k > ceil(n / 2.0) * ceil(n / 2.0) + (n / 2) * (n / 2)) {
cout << "NO";
return 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
a[i][j] = 'S';
}
}
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int h0, h1;
struct line {
int p;
int type;
double a, b;
};
line data[100];
int go(int h0, int h1, int f) {
int ret = 0;
for (int i = 1; i <= 100; ++i) {
int y = -100 * i;
if (i % 2)
y += 100 - h1;
else
y += h1;
double a = (y - h0... | 12 |
/*
*
*
* Copyright 2021 Tanishk <tanishktonk>
* ........ ;)
*
*
*
*/
#include <bits/stdc++.h>
#define ll long long int
#define fr(i,n) for(i=0;i<n;i++)
#define rng(i,a,b) for(i=a;i<b;i++)
#define T long long int T;cin>>T;while(T--)
#define ain(a,n) for(int zzz=0;zzz<n;zzz++){cin>>a[zzz];}
#define aout(a,n)... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100500;
int n, A[MAXN];
vector<int> G[MAXN], W;
map<int, int> L;
int depth[MAXN];
void bfs(int je) {
queue<int> Q;
Q.push(0);
while (Q.size()) {
int p = Q.front();
Q.pop();
if (depth[p] % 2 == je)
W.push_back(A[p]);
else
L[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = ~(((long long)0x1) << 63) / 2;
const int INF = 0X3F3F3F3F;
const double eps = 1e-7;
const long long MOD = 1000000007;
char str[1100];
int k;
long long dp[1100][1100][3];
long long dfs(int pos, int p, int s, int ok) {
if (pos == -1) return ok == 2;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
long long n;
cin >> n;
bool prime = 1;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
prime = 0;
break;
}
}
if (prime) {
cout << 1 << "\n";
cout << 0 << "\n";
return ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> id;
int main() {
int n, k;
cin >> n >> k;
int a[n];
bool taken[108];
for (int i = 0; i < 108; ++i) taken[i] = false;
int l = 0;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
if (l == k) break;
if (!taken... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 998244353;
void Add(int &a, int b) { a = (a + b) >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
const int N = 35, M = 21;
int n, m, f[2][M][M][M][M][2][2];
int x[N], y[N];
int dx[N], dy[N], tx[N], ty[N];
int... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int f1 = 0, f2 = 1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
for (int j = 1; j <= n; j++) {
cout << f1 << ' ';
f1 += 2;
}
else
for (int j = 1; j <= n; j++) {
cout << f2 << ' ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int x, y, z;
cin >> x >> y >> z;
if (x == y && y == z) {
cout << "YES\n";
cout << z << " " << z << " " << z;
} else if (x == y && x > z) {
cout << "YES\n";
cout << x << " " << z << " "... | 0 |
#include <bits/stdc++.h>
int main() {
int n, s = 0;
scanf("%d", &n);
int a[n][n];
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
scanf("%d", &a[i][j]);
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j)
s = s + a[i][j];
else if (i +... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long opt[61][61][61];
int g[61][61], Max[61], Min[61];
int inf = 100000000;
int g1, g2, s1, s2, b1, b2;
int canG[61], canS[61], canB[61];
long long ans = 0LL;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) g[i]... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long f[2000100ll] = {0}, sum[2000100ll] = {0};
int sp[2000100ll];
int main() {
for (int i = 1; i < 2000100ll; ++i) {
if (i & 1)
sp[i] = i;
else
sp[i] = 2;
}
for (int i = 3; i * i < 2000100ll; ++i) {
if (sp[i] != i) continue;
for (int j... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &t) {
t = 0;
char c = getchar();
long long f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -f;
c = getchar();
}
while (c >= '0' && c <= '9') {
t = (t << 3) + (t << 1) + c - '0';
c = getchar();
}
... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n >> s;
for (int i = 0; i < s.length(); ++i)
if (i % n == 0) s[i] = 'q';
if (s.length() < 5)
cout << 0 << endl;
else {
int total = 0;
for (int i = 3; i < s.length(); ++i) {
if (s[i] != 'r') {
if (i %... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, best[2105];
pair<int, int> A[2105];
vector<int> bad;
char B[2105][2105];
void go(int x1, int x2, vector<int> bad) {
int mid = (x1 + x2) >> 1;
int up[2105], down[2105];
for (int j = 1; j <= m; j++)
if (B[mid][j] == '.') {
up[j] = mid;
while... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int T;
cin >> T;
while (T--) {
long long int a, b, c;
cin >> a >> b >> c;
long long int answer = INT_MAX, A, B, C;
for (l... | 12 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1001];
vector<int> ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cnt[i] = i;
}
for (int i = 1; i <= n; i++) {
if (cnt[i] > 1) {
for (int j = i + i; j <= n; j += i) {
cnt[j] /= cnt[i];
}
ans.push_back(i)... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 100;
pair<long long, long long> a[maxn];
long long maxs[2];
long long sum, n;
int main() {
cin >> n;
for (long long y = 0; y < n; y++) {
long long i, j;
cin >> i >> j;
a[y] = pair<long long, long long>(i, j);
sum += i;
if (... | 3 |
#include <bits/stdc++.h>
const int N = 2e5 + 10;
using namespace std;
const int inf = 0x3f3f3f3f;
int l[N], r[N];
int main() {
int n, p;
while (cin >> n >> p) {
for (int i = 0; i < n; i++) scanf("%d%d", &l[i], &r[i]);
l[n] = l[0], r[n] = r[0];
double ans = 0.0;
for (int i = 0; i < n; i++) {
do... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct _ {
ios_base::Init i;
_() {
cin.sync_with_stdio(0);
cin.tie(0);
}
} _;
void advance(bool &to_right, int &next_stop, int N) {
if (to_right && next_stop == N - 1) {
to_right = false;
next_stop = N - 2;
} else if (!to_right && next_stop == 0) {... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long inline read() {
long long num = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) {
num = (num << 3) + (num << 1) + c - '0';
c = getchar();
}
return num * neg;
}
const lo... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, D;
scanf("%d %d", &N, &D);
vector<pair<int, int> > v;
for (int i = 0; i < N; i++) {
int temp1, temp2;
scanf("%d %d", &temp1, &temp2);
v.push_back(make_pair(temp1, temp2));
}
sort(v.begin(), v.end());
long long maxm_fac = v[0].se... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 7;
int dp[N][N][2][2];
int len[N];
vector<int> v[N];
int f(int idx, int sum, int r, int s, int lim, vector<int> &d) {
if (idx < 0) return r == 0 && sum == 0 && s;
int lb = r ? d[idx] : 0;
int res = 0;
if (~dp[idx][sum][r][s]) return dp[idx][sum][... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % 998244353;
y = y >> 1;
x = (x * x) % 998244353;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dp[101][2];
int n, k, d;
long long fun(int nn, int is) {
if (nn == n) return is;
if (dp[nn][is] != -1) return dp[nn][is];
dp[nn][is] = 0;
long long ans = 0;
for (int i = 1; i <= k; i++) {
if (nn + i <= n) {
ans += fun(nn + i, is | (i >= d));
... | 8 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
}
long long modpow(long long a, long long p, long long mod) {
long long ret = 1;
while (p) {
if (p & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
p /= 2;... | 15 |
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define test(x) cout << "Line(" << __LINE__ << ") " #x << ' ' << x << endl
#define printv(x) {\
for (auto i : x) cout << i << ' ';\
cout << endl;\
}
#define pii pair <int, int>
#de... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 5005;
const int MOD = 998244353;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
void msm() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
int fact(long long x);
int sol(... | 1 |
#include <bits/stdc++.h>
long long min = 2e18;
void count(long long b, long long d, long long s) {
long long max =
((b) > (((d) > (s) ? (d) : (s))) ? (b) : (((d) > (s) ? (d) : (s))));
long long missed = max - b + max - d + max - s;
if (min > missed) min = missed;
}
int main() {
long long b, d, s;
scanf(... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
inline int pow_(long long a, int n, int p = mod) {
int r = 1;
while (n) {
if (n & 1) r = r * a % p;
n >>= 1;
a = a * a % p;
}
return r;
}
inline int inv_(int a) { return pow_(a, mod - 2, mod); }
inline int add(int a, int... | 15 |
#include <bits/stdc++.h>
const int MAXN = 100 + 5;
std::multiset<std::string> S;
std::string str, ans;
int del[MAXN], tt[MAXN];
std::vector<std::string> SS;
inline bool cmp(std::string a, std::string b) {
return a.length() < b.length();
}
int main() {
int n;
std::cin >> n;
std::cout << "? 1 " << n << std::endl;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, m;
double a[300 + 10][3000 + 10], b[300 + 10][3000 + 10], c[3000 + 10],
d[300 + 10], ans = 0;
int main() {
int i, j, k;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; ++i)
for (j = 1; j <= m; ++j) {
scanf("%d", &k);
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int LG = 50;
long long w, m;
long long a[LG];
int main() {
bool flag = true;
cin >> w >> m;
int sz = 0;
while (m) {
a[sz++] = m % w;
m /= w;
}
for (int i = 0; i <= sz; i++) {
if (a[i] ^ 0 && a[i] ^ 1 && a[i] ^ (w - 1) && a[i] ^ w) {
flag ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> neigh[(1 << 20)];
vector<double> rat;
bool fort[1 << 20];
bool used[(1 << 20)];
int cntFN[(1 << 20)];
vector<int> cset;
priority_queue<pair<double, int> > q;
vector<int> ans;
void getAns() {
for (int i = 1; i <= n; i++) {
if (fort[i] || used[i... | 15 |
#include <bits/stdc++.h>
const long long int INF = 1e9 + 999, MOD = 1e9 + 7, MAXN = 200000;
const long double EPS = 0.000001;
using namespace std;
bool palindrom(string s) {
bool ok = true;
for (long long int i = 0; i < (long long int)s.size(); i++) {
if (s[i] != s[(long long int)s.size() - i - 1]) ok = false;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool eq(string a, string b) {
set<string> v;
v.insert(b);
string c = b;
c[2] = b[4];
c[3] = b[5];
c[4] = b[3];
c[5] = b[2];
v.insert(c);
c = b;
swap(c[2], c[3]);
swap(c[4], c[5]);
v.insert(c);
c = b;
c[2] = b[5];
c[3] = b[4];
c[4] = b[2];
c... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.