solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int f[410000];
int vis[410000];
int sum = 0;
int finds(int x) { return x == f[x] ? x : f[x] = finds(f[x]); }
void unions(int x, int y) {
x = finds(x);
y = finds(y);
if (x != y) f[x] = y;
return;
}
int main() {
int n, m, q;
int x, y;
cin >> n >> m >> q;
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int N = 100000 + 10;
vector<int> e[N];
struct State {
int v, q;
State() {}
State(int a, int b) : v(a), q(b) {}
} q[N * 100];
int head, tail;
int isV[N];
int k, S, T;
bool bfs(int m) {
head = tail = 0;
int dis[N];
memset((dis),... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(2*b==a+c){cout<<"YES";}
else{cout<<"NO";}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
template <typename T>
inline void read(T &r) {
static char c;
r = 0;
int f = 1;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
if (c == '-') f = -1;
for (; c >= '0' && c <= '9';
r = (r << 1) + (r << 3) + (c ^ 4... | 3 |
#include<stdio.h>
int main(void){
int a,n;
scanf("%d%d",&n,&a);
printf("%d",n*n-a);
return 0;
} | 0 |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MM = int(2e5) + 5;
const string io_file = "";
int n;
int a[MM];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
long long m = -1;
cin >> a[0];
for (int i = 1; i < n; i++) {
cin >> a[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[123456];
int a[2][2];
int main() {
long long sum1 = 0, sum2 = 0;
gets(s);
for (int i = 0; s[i]; i++) {
int x;
if (s[i] == 'a')
x = 1;
else
x = 0;
++a[x][i & 1];
sum1 += a[x][i & 1];
sum2 += a[x][(i & 1) ^ 1];
}
cout << su... | 4 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
int count;
cin >> count;
int p[count];
for (int i = 0; i < count; ++i) {
cin >> p[i];
--p[i];
}
vector<int> cycles[count + 1];
vector<int> paths[count];
int representative[count];
int arr[count];
for (int i = 0; i < count; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct dsu {
vector<int> p, h, s;
dsu(int n) {
p.resize(n);
h.resize(n, 0);
s.resize(n, 1);
for (int i = 0; i < n; ++i) {
p[i] = i;
}
}
int top(int v) {
if (p[v] == v) return v;
return p[v] = top(p[v]);
}
void unite(int a, int b... | 4 |
#include <bits/stdc++.h>
const int N = 100100;
const int Q = 250200;
const long long mod = 1e9 + 7;
using namespace std;
int n;
long long mx = 1e9;
long long best[N][26];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
for (int j = 0; j < 26; j++... | 5 |
#include <bits/stdc++.h>
using namespace std;
char *p1, *p2;
;
char buffer[100005];
template <class T>
void read(T& x) {
char ch = ((p1 == p2 &&
(p2 = (p1 = buffer) + fread(buffer, 1, 100005, stdin), p1 == p2))
? EOF
: *p1++);
x = 0;
while (!('0' <= ch && ch <= '9')... | 5 |
//
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)
typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;
const int N = (1 << 18)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 4 |
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+5;
struct point {
int id,l,r,bl;
}q[300005];
int num[maxn],a[maxn],t[maxn];
int sz;
int ans[maxn]; //答案
int cnt;//是当前区间众数出现次数
bool cmp(point a,point b){
return a.bl==b.bl?a.r<b.r:a.bl<b.bl;
}
void add(int i){
t[num[a[i]]]--;
num[a[i]]++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n < 6 or n % 2 == 1) {
cout << 0;
return 0;
}
long long k = n / 2;
long long t = k / 2 + 1;
long long last_words;
last_words = k - t;
cout << last_words;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int s;
int w;
cin>>s>>w;
if(w>=s)
cout<<"unsafe";
else
cout<<"safe";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
double dot(complex<doub... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int add(int x, int y) { return x += y, x >= mod ? x - mod : x; }
inline int sub(int x, int y) { return x -= y, x < 0 ? x + mod : x; }
int f[55][55][2], a[55], len;
int main() {
int n;
scanf("%d", &n);
if (!n) a[++len] = n;
while (n) a... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
out << "[";
for (auto it = a.begin(); it != a.end... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d, e;
cin >> a >> b >> c >> d >> e;
for (int i = c; i <= d; i++) {
if (i * e <= b && i * e >= a) {
cout << "YES";
return 0;
}
}
cout << "NO";
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i = 0, j = 1, k = 0;
while (i < s.length()) {
while ((j < s.length()) && (s[j] == s[j - 1])) j++;
if ((j - i) % 2 == 0) k++;
i = j;
j++;
}
cout << k;
return 0;
}
| 1 |
#include <iostream>
#include <algorithm>
using namespace std;
int H, W;
int wall;
int M[102][102];
bool visited[102][102];
const int dx[2][6] = {{ 1,-1, 0, 0,-1,-1},{ 1,-1, 0, 0, 1, 1}};
const int dy[2][6] = {{ 0, 0, 1,-1,-1, 1},{ 0, 0, 1,-1,-1, 1}};
bool isInField(int x, int y) {
return 0<=x&&x<=W+1 && 0<=y&&y<=H... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long sear(long long l, long long r, long long x, vector<long long> &pr) {
while (l <= r) {
long long m = (l + r) / 2;
if (pr[m] <= x)
l = m + 1;
else
r = m - 1;
}
return l;
}
int main() {
ios_base::sync_with_stdi... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, d[300000], dr[300000], r[300000], rr[300000], lr[300000];
vector<int> e[300000], er[300000];
vector<int> ver[300000];
int main() {
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> r[i];
if (r[i] == 0)
lr[i] = 1, rr[i] = k;
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char use[62] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C',
'D', 'E', 'F', ... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool visited[100100][2];
vector<long long> g[100100], vec;
long long par[100100][2];
bool v[100100], v2[100100];
bool chckcycle(long long src) {
long long i;
v[src] = 1;
v2[src] = 1;
for (i = 0; i < g[src].size(); i++)
if (!v[g[src][i]]) {
if (chckcycle(g[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int eval(char *sx, char *sy, int base) {
int x = 0;
for (int i = 0; i < strlen(sx); i++) {
x *= base;
x += sx[i] - '0';
}
int y = 0;
for (int i = 0; i < strlen(sy); i++) {
y *= base;
y += sy[i] - '0';
}
int res = x + y, ct = 0;
while (res > 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << n << "\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans;
int main() {
cin >> n >> k;
ans = 1;
for (int i = 1; i < k; i++) ans = (ans * k) % (int)(1e9 + 7);
for (int i = 1; i <= n - k; i++) ans = (ans * (n - k)) % (int)(1e9 + 7);
cout << ans;
return 0;
}
| 4 |
#include <iostream>
#include <map>
using namespace std;
int T;
map<int, bool> d;
int main(){
for(int i=0;i<143;i++){
for(int j=0;j<143;j++){
int t = i * i + j * j;
if(1 < t && t < 20000) d[t] = true;
}
}
map<int, bool>::iterator iti, itj;
for(iti=d.begin();iti!=d.end();iti++){
if(!iti... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, i, j, k, flag = 1, sum = 0;
cin >> n;
long long ara[n], ara2[n];
for (i = 0; i < n; i++) {
cin >> ara[i];
sum += ara[i];
}
for (i = 0; i < n; i++) cin >> ara2[i];
sort(ara2, ara2 +... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
os << "(" << v.first << " " << v.second << ")";
return os;
}
template <typename T, typename U = typename T::value_type,
typename = typename enable_if<!is_same<T, string>::v... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
int N, M, Q;
while ( cin >> N >> M >> Q, N ) {
vector<int> s(N, 0);
vector<vector<int> > b(M, vector<int>(36, 1));
while ( Q--... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > a;
vector<int> psum;
int main() {
if (0) {
freopen("CP.inp", "r", stdin);
freopen("CP.out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin >> n >> m;
a = vector<vector<int> >(m + 1, vector<int>());
psum = vector<int>... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> A(n);
for (auto &a : A) cin >> a;
vector<int> F(32);
for (auto a : A)
for (int i = 0; i < 32; i++) F[i] += (a >> i) & 1;
int bst{}, ans{};
for (int j = 0; j < n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
istream &operator>>(istream &is, vec... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long modulo(long long base, long long exponent, long long modulus);
long long choose(long long n, long long k);
long long inverse(long long a, long long m);
void build();
void fileio();
long long ncr(long long n, long long r);
const int nax = 1e6 + 10;
const int LG = l... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k, a, b;
scanf("%d%d%d", &k, &a, &b);
printf("%s\n", ((b/k)==((a-1)/k))?"NG":"OK");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int d, l, k;
cin >> d >> l;
k = d/l;
cout << k+d%l << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int MOD;
struct mint {
long long n;
mint(long long n_ = 0) : n(n_ % MOD) {
if (n < 0) n += MOD;
}
};
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265358979323846;
long long MOD = 1e9 + 7;
const char nl = '\n';
const long long inf = 1e15;
long long mul(long long x, long long y) {
return (1ll * (x % MOD) * (y % MOD));
}
long long modpow(long long x, long long y) {
long long z = 1;
wh... | 3 |
#include<bits/stdc++.h>
#define ll long long
const int N = 100010;
int n, a[N], b[N];
int main(){
scanf("%d", &n);
for (int i = 0; i < n; ++ i){
scanf("%d%d", &a[i], &b[i]);
}
ll ans = 0;
for (int i = n - 1; i >= 0; -- i){
ll now = ans + a[i];
ans += (b[i] - now % b[i]) % b[i];
}
return printf("%lld\... | 0 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 86400
int main(){
int n, t[MAX+1];
while(cin >> n, n){
memset(t, 0, sizeof(t));
int H1, H2, M1, M2, S1, S2;
for(int i = 0 ; i < n ; i++){
scanf("%d:%d:%d %d:%d:%d", &H... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 50;
vector<int> g[N];
bool win[N];
bool los[N];
bool mark[N];
int deg[N];
int a[N], b[N];
int n, k1, k2;
void dfs(int v) {
mark[v] = true;
if (v < n)
for (int i = 0; i < k2; i++) {
int to = (v - b[i] + n) % n + n;
if (!mark[to]) {
... | 3 |
#include <bits/stdc++.h>
long long exp(long long x, long long y, long long p) {
long long res = 1;
while (y) {
if (y % 2) res = (res * x % p) % p;
x = (x * x) % p;
y /= 2;
}
return res;
}
long long expo(long long x, long long y) {
long long res = 1;
while (y) {
if (y % 2) res = (res * x % ((... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
while (1) {
if (a == 0 || b == 0) {
break;
}
if (a >= 2 * b) {
long long x = (a / (2 * b));
a -= 2 * b * x;
} else if (b >= 2 * a) {
long long x = (b / (2 * a));
b -= 2 * a * x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e5;
int mul(int a, int b) { return (int)((a * (long long)b) % MOD); }
int Pow(int a, unsigned deg) {
if (deg == 0) return 1;
if (deg == 1) return a;
int r = Pow(a, deg / 2);
r = mul(r, r);
if (deg & 1) r = mul(r... | 4 |
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string a, b;
int dp[4005][4005] = { 0 };
int main() {
while (cin >> a >> b) {
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < b.size(); j++) {
if (a[i] == b[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
}
else dp[i ... | 0 |
#include <bits/stdc++.h>
int main() {
uint32_t a, b, c;
scanf("%d %d %d", &a, &b, &c);
printf("%g", ceil((double)(a * c - b * c) / b));
return 0;
}
| 1 |
#include <bits/stdc++.h>
const long long P = 1e9 + 7;
const double EPS = 1e-9;
using namespace std;
class LIS {
public:
int n;
vector<int> v;
vector<int> par;
vector<int> incrSubSeq;
vector<int> incrSubSeqIndx;
LIS(vector<int> &arr) : n(arr.size()), v(arr) { par.assign(n, 0); }
void run() {
incrSubSe... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
void solve() {
long long W, H;
cin >> W >> H;
long long x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
long long w, h;
cin >> w >> h;
long long ans = INT64_MAX;
bool f = (w + (x2 - x1)) <= W;
bool g = (h + (y2 - y1)) <= H;
if ((w + (... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
char s[N];
char s1[N];
int n;
int fromid[N];
int main() {
scanf("%s", s);
n = strlen(s);
for (int i = 0; i < n; i++) s1[i] = (i % 26) + 'a';
printf("? %s\n", s1);
fflush(stdout);
scanf("%s", s1);
for (int i = 0; i < n; i++) fromid[i] = s1[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[103][205][2][55];
char ch[103];
int main() {
memset(dp, 0, sizeof(dp));
scanf("%s", ch + 1);
int p;
scanf("%d", &p);
int n = strlen(ch + 1);
int i;
dp[0][100][1][0] = 1;
for (i = 0; i <= n - 1; i++) {
int j;
for (j = 0; j <= 200; j++) {
... | 3 |
#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... | 4 |
#include <bits/stdc++.h>
int lens = 0, pos1 = 0, pos2 = 0, mmod = 10;
long long a, b, c, mod = 1000000007;
long long hash[1000002], base[1000002];
char s[1000002];
bool check() {
a = (hash[pos1] - hash[0] * base[pos1] % mod + mod) % mod;
b = (hash[pos2] - hash[pos1] * base[pos2 - pos1] % mod + mod) % mod;
c = (ha... | 6 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
class SuffixArray{
string s;
vector<int> sort_idx, rev;
public:
// 接尾辞配列を作る
SuffixArray(const string &str) : s(str) {
int n = s.size();
s.push_back('$');
sort_idx.resize(n+1);
... | 0 |
#include <bits/stdc++.h>
#define NIL NULL
#define INF 1000000001
using namespace std;
struct node {
int key,priority;
struct node *right;
struct node *left;
};
typedef node * Node;
Node delete_(Node t,int key);
Node _delete(Node t,int key);
Node rightRotate(Node t){
Node s = t->left;
t->left ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int bl = 1100, sz = 1e5 + 10, sz2 = 500, inf = 1e9;
int l[sz], r[sz], ar[sz];
vector<int> sq[sz2], sq2[sz2], pref[sz2], pref2[sz2];
set<int> se[sz];
bool comp(int a, int b) { return l[a] < l[b]; }
bool comp2(int a, int b) { return r[a] > r[b]; }
void build(vector<int>... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define eb emplace_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S seco... | 5 |
#include <iostream>
using namespace std;
int isintersecter(double x1,double y1,double x2,double y2,double px,double py,
double qx,double qy){
if(((py-y1)*(x1-x2)-(y1-y2)*(px-x1))*((qy-y1)*(x1-x2)-(y1-y2)*(qx-x1)) < 0)return 1;
else return 0;
}
int main(){
double x1,y1,x2,y2,x3,y3,xp,xy;
while(cin>>x1>>y1>>x... | 0 |
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 40000
#define sqrt_NUM 200
typedef pair<int,int> P;
enum Type{
ADD,
DELETE,
QUERY,
};
struct Info{
Type type;
int fro... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, m, i, j, k, a, b, c, x;
cin >> t;
a = 1234567;
b = 123456;
c = 1234;
for (i = 0; i < (t / a + 1); i++) {
for (j = 0; j < (t / b + 1); j++) {
if ((t - i * a - j * b) >= 0 && (t - i * a - j * b) % c == 0) {
cout << "Y... | 2 |
#include<iostream>
using namespace std;
int main()
{
int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
int k;
cin >> k;
cout << a[k - 1] << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long n = s.size();
long long sum1 = 0, sum2 = 0, sum3 = 0, z = 0;
for (long long i = 0; i < n - 2; i++) {
if (((s[i] - '0' + s[i + 1] - '0' + s[i + 2] - '0') == 54) &&
(s[i] != s[i + 1] && s[i] != s[i + 2])) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> mx, my;
long long int ans = 0;
map<pair<long long int, long long int>, long long int> cnt;
void solve() {
long long int n;
cin >> n;
long long int x, y;
for (long long int i = 0; i < n; i++) {
cin >> x >> y;
mx[x]++;
my[... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
const... | 0 |
// Problem: A. Strange Functions
// Contest: Codeforces - Educational Codeforces Round 99 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1455/problem/A
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double h, w;
cin >> h >> w;
float rat = float(h) / float(w);
if (rat > 1.25) {
if ((ceil(log2(w)) == floor(log2(w))) ? 1 : 0) {
h = floor(w * 1.25);
} else {
if (!(ceil(log2(h)) == floor(log2(h))) ? 1 : 0) h = pow(2, int(log2(h)));
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k, t, x, y;
cin >> n >> m >> k >> t;
for (int i = 0; i < k; i++) {
cin >> x >> y;
v.push_back((x - 1) * m + y);
}
sort(v.begin(), v.end());
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[1000010], u[1000010], poz[1000010];
int n, m, x, y, i, j, k, a[1000010];
bitset<1000010> viz;
bool comp(int a, int b) { return a > b; }
void dfs(int i) {
viz[i] = 1;
u[k].push_back(a[i]);
poz[k].push_back(i);
for (auto it : v[i])
if (!viz[it]) dfs(... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define MAXN
int main()
{
int n,a;
cin>>n>>a;
if(n%500<=a) puts("Yes");
else puts("No");
}
| 0 |
#include "bits/stdc++.h"
using namespace std;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
const int dx2[4] = { -1,0,2,1 };
const int dy2[4] = { 0,2,1,-1 };
struct aa {
int x;
int y;
int turn;
};
int getdis(const vector<vector<int>>&field, const int fx, const int fy,const int gx,const int gy) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int n, m, A, B, T, U[maxn], V[maxn];
int dis[maxn][maxn], pass[maxn][maxn];
int g[maxn], f[maxn];
bool vis[maxn];
bool OnRoad(int S, int x, int T) { return dis[S][x] + dis[x][T] == dis[S][T]; }
int dfs(int u, int T) {
if (u == T) return f[u];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s, t;
cin >> n >> s >> t;
int arr[n];
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
}
int shuffles = 1;
int currentCup = s;
int found = 0;
if (s == t) {
cout << 0 << endl;
} else {
for (; shuffles <= n + 1; ++shuffles) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> graph(2e5 + 1);
vector<long long int> pa(2e5 + 1, -1);
vector<map<long long int, long long int>> sz(2e5 + 1);
vector<long long int> ma(2e5 + 1, -1);
void aps554() {}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)(1e6) + 322;
const long long inf = (long long)1e13;
const long long mod = 1000000007;
const double eps = 1e-9;
long long ans, n, a[N], w;
void calc(long long id, long long sum) {
if (id == 0) {
ans = max(ans, sum);
return;
}
long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a[111], kol;
int main() {
cin >> n;
while (n) {
a[kol++] = n % 10;
if (a[0] == 1) {
kol = 0;
for (int i = 0; i < 111; i++) a[i] = 0;
}
if (a[0] == 4 && a[1] == 4 && a[2] == 1) {
kol = 0;
for (int i = 0; i < 111; i++) a[i] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4002;
int dp[N][N],cost[N][N],n,rem[2] = {1,1};
pair<int,int>a[2][N];
char c;
int main(){
//freopen("readin.txt","r",stdin);
scanf("%d",&n);
for(int i = 1;i <= 2*n;i++){
scanf(" %c",&c);
scanf("%d",&a[c == 'B'][rem[c == 'B']].first);
a[c == 'B'][rem[c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 998244353;
long long f[55][N], l[N], r[N], sum[N], prim[N], nump, vis[N], mu[N];
void init() {
mu[1] = 1;
for (int i = 2; i < N; i++) {
if (!vis[i]) {
prim[++nump] = i;
mu[i] = -1;
}
for (int j = 1; j <= nump && i * p... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline int _sread(char *s) {
char c = getchar();
int len = 0;
for (; !(c >= 'a' && c <= 'z'); c = getchar())
;
for (; c >= 'a' && c <= 'z'; s[++len] = c, c = getchar())
;
s[++len] = 0;
return len - 1;
}
const int P = 1e9 + 7;
const int N = 2005;
inline v... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int n, dp[MAXN][MAXN][2];
pair<int, int> a[MAXN];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d %d", &a[i].first, &a[i].second);
sort(a, a + n);
for (int i = n; i >= 0; i--)
for (int j = 0; j <= n; j++)
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[50];
double dp[51][51][51];
bool viz[51][51][51];
long long choose[51][51];
double go(int i, int j, int k) {
if (i == m - 1) return j <= a[i] * k;
double &d = dp[i][j][k];
if (viz[i][j][k]) return d;
double res = 0;
for (int l = 0; l <= min(j, a[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int main() {
int n, k, edge;
vector<int> e[maxn];
vector<int> dis[maxn];
cin >> n >> k;
int maxj = 0;
for (int i = 1; i <= n; i++) {
int j;
cin >> j;
maxj = max(j, maxj);
dis[j].push_back(i);
}
if (dis[0].size() != ... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
int wyn;
vector<int> g[100005];
bitset<100005> v;
bool dodaj;
void dfs(int x, int from) {
v[x] = true;
for (int i = 0; i < (((int)(g[x]).size())); ++i) {
if (g[x][i] != from) {
if (!v[g[x][i]]) {
dfs(g[x][i], x);
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long ans = 0;
unordered_map<int, int> m1;
unordered_map<int, int> m2;
while (n--) {
int x, y;
cin >> x >> y;
m1[x - y]++;
m2[x + y]++;
}
for (auto i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
if (a >= b)
return (a);
else
return (b);
}
int main() {
int n;
cin >> n;
int a[n + 1];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> ans;
for (int i = 1; i <= n; i++) {
int flag = true;
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <class T>
inline ... | 5 |
#include <bits/stdc++.h>
int main() {
static double dp[201][201] = {0.};
int n, k, a;
scanf("%d %d %d", &n, &k, &a);
double p = a / 100.;
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= k; j++) {
if (i == 0) {
for (int x = n + j; x % 2 == 0; x /= 2) dp[0][j] += 1.0;
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
int power[555];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> power[i];
queue<int> line;
for (int i = 2; i <= n - 1; i++) line.push(i);
int p1 = 0;
int p2 = 1;
int consec... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e5 + 5;
int main() {
int t;
cin >> t;
double a[1005], b[1005];
for (int i = 1; i <= t; ++i) {
int d;
cin >> d;
if (d < 4 && d > 0) {
a[i] = -1;
b[i] = -1;
continue;
}
double discr = sqrt((d * d - 4 * d) * 1.0)... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void gn(T &x) {
static char c, s;
s = 0;
while (c = getchar(), (c < '0' || c > '9') && c != '-')
;
if (c == '-') s = 1, c = getchar();
for (x = 0; c >= '0'; x = (x << 1) + (x << 3) + c - '0', c = getchar())
;
if (s) x = -x;
}
inline vo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k, j;
cin >> n >> k;
set<long long> ms;
long long x = 0;
for (i = 0; i < n; i++) {
cin >> j;
if (ms.find(j) == ms.end()) {
ms.insert(j);
x += j;
}
}
j = 0;
for (auto it : ms) {
if (k <= 0 || x <= 0) break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int N;
ll cnt, cntx, cnty;
vector<bool> used(200000, 0);
vector<vector<int> > G(200000 + 10);
void dfs(int idx, int par){
used[idx] = true;
if(idx < 100000) cntx++;
else cnty++;
for(au... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
vector<long long> fact(long long x) {
vector<long long> ans;
long long wx = x;
for (long long i = 2; i * i <= wx; i++) {
long long cnt = 0;
while (x % i == 0) {
cnt++;
x /= i;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct seg {
int x1, y1, x2, y2;
seg() {}
seg(int _x1, int _y1, int _x2, int _y2)
: x1(_x1), y1(_y1), x2(_x2), y2(_y2) {}
} H[100005], V[100005];
int ay[100005 << 2], ax[100005 << 2], ft[100005 << 2];
vector<int> v[100005 << 2];
bool cmpx(seg t1, seg t2) {
if ... | 4 |
#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
long long int n, sum;
scanf("%lld", &n);
if (n % 2 == 0) {
sum = n / 2;
}
if (n % 2 == 1) {
sum = -(ceil(n / 2) + 1);
}
printf("%lld\n", sum);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = LLONG_MAX;
int prime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return 0;
}
return 1;
}
void solve() {
int n;
cin >> n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0 && prime(i)) {... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.