solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
void solve() {
long long n, i, l, ans = 0, k;
cin >> n >> k;
vector<long long> a;
for (long long i = 0; i < n; i++) {
... | 2 |
#include<iostream>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m){
if(n==0&&m==0)
break;
int ans=0;
for(int i=n;i>0;i--){
for(int j=i-1;j<i&&j>0;j--)
for(int k=j-1;k<j&&k>0;k--){
if(i+j+k==m){
ans++;
}
}
}
cout<<ans<<endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
struct FastSet {
vector<long long> list;
vector<long long> pos;
void init(long long N) {
pos.resize(N, -1);
list.reserve(N);
}
void insert_all() {
list.clear();
list.resize(pos.size());
for (long long i = 0; i < list... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Read(T &n) {
char c;
bool nega = 0;
n = 0;
do {
c = getchar();
} while (c != '-' && !isdigit(c));
if (c == '-') {
nega = 1;
c = getchar();
}
do {
n = n * 10 + c - '0';
} while (isdigit(c = getchar()));
if (nega)... | 5 |
#include <bits/stdc++.h>
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class T>
void cxk(T& a, T b) {
a = a > b ? a : b... | 4 |
#include <bits/stdc++.h>
char f[100][10002];
int main() {
int h, w;
int i, j;
scanf("%d %d", &h, &w);
for (i = 0; i < h; i++) {
f[i][0] = '#';
f[i][w + 1] = '#';
for (j = 1; j <= w; j++) scanf(" %c", &f[i][j]);
}
int pos = 1;
int d = 1;
long long ans = 0;
for (i = 0; i < h - 1; i++) {
ne... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
scanf("%d", &n);
printf("%d\n", (n - 1) / 2);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
typedef struct _Char {
char c;
int row, col;
} Char;
bool char_comp(Char c1, Char c2) { return c1.c < c2.c; }
int main(int argc, char* argv[]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long n;
cin >> n;
vector<long long> a(n);
for (long long &i : a) cin >> i;
long long ans = -1e18;
for (long long i = 0; i < n; i++) {
long long c = 0;
while (a[i % n] == 1) c+... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, b[N], a[N];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;++i) scanf("%d",b+i);
for(int i=1;i<=n;++i) {
for(int j=n-i+1;j>=1;--j)
if(b[j]==j) {
a[i]=j; break;
}
if(!a[i]) return puts("-1"),0;
for(int j=a[i];j<=n-i;++j) b[j]=b[j+1... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Each_prime {
int pri, num;
friend bool operator<(Each_prime p, Each_prime q) { return p.pri < q.pri; }
} a[3][35];
int len[3];
int l[3][1000000 + 5];
void work(int x, int num) {
for (int i = 2; i * i <= num; i++) {
if (num % i == 0) {
if (l[x][i] > 0)... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll q, h, s, d; cin >> q >> h >> s >> d;
ll n; cin >> n;
ll X = min(2*min(2*q, h), s);
ll XL = min(2*X, d);
cout << n%2*X+n/2*XL << endl;
} | 0 |
#include<iostream>
int n,x=2;
int main(){
for(std::cin>>n;n>=x;)x*=2;
std::cout<<x/2;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
for(int i=1; i<=9; i++){
if(N%i==0&&N/i<10){
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
} | 0 |
#include <iostream>
using namespace std;
int main(){
int m, n;
cin >> m >> n;
cout << (m==n ? "Yes" : "No");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string w;
int i;
cin >> w;
locale l;
for (i = 0; i < w.length(); i++) {
if (toupper(w[i]) != 'A' && toupper(w[i]) != 'E' && toupper(w[i]) != 'U' &&
toupper(w[i]) != 'I' && toupper(w[i]) != 'O' && toupper(w[i]) != 'Y')
cout << "." << ... | 1 |
#include<bits/stdc++.h>
long long n,a,f[(int)2e5+10],s;
int main(){
scanf("%lld",&n);
for(int i = 1; i <= n; ++i){
scanf("%lld",&a);
if(i&1)s+=a; // s is sum of odd indices
if(i == 1)continue;
if(i&1)f[i] = std::max(f[i-2]+a,f[i-1]); // at odd place either f[i-2]+a (common sense)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int A, B, L, M, C, D, x = 1;
cin >> A >> B >> L;
C = L % A;
D = (C - B);
M = L - D;
if (M <= L) {
cout << M << endl;
} else {
while (M > L) {
M = M - x * A;
x++;
... | 1 |
#include <bits/stdc++.h>
int n;
int a[500001];
int p1 = 0;
int stamin[500001];
int p2 = 0;
int stamax[500001];
int tree[500001 << 2];
int treecnt[500001 << 2];
int lazy[500001 << 2];
long long ans = 0;
void inline add(int x, int k) {
tree[x] += k;
lazy[x] += k;
}
void inline push_up(int x) {
tree[x] = std::min(tr... | 6 |
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 3010
#define MOD 1000000007
#define INV 500000004
inline void trim(int &x) { (x >= MOD) && (x -= MOD); }
inline void up(int &x, int y) { trim(x += y); }
int n, q, b = 1, ans = 0, a[MAXN], f[MAXN][MAXN];
int main() {
scanf("%d%d",... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
struct node {
int x, y;
char c;
void put() { printf("(%d,%d) : %c\n", x, y, c); }
} a[30];
int step[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int work[100005][2];
char s[1005];
int mp[1005][1005], n, m, k, top, h[1005][1005], l[1005][1005];
bool okh(int H,... | 4 |
#include <bits/stdc++.h>
int n, a[1005], maxi[1005];
char map[1005][1005];
int main() {
int i, j, max, min, maxy, miny, cur, f, x, y;
char ch;
scanf("%d", &n);
cur = 0;
f = -1;
max = 0, min = 0;
memset(map, ' ', sizeof(map));
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
f *= -1;
cur += f * ... | 3 |
// ARC085D.cpp
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2020;
int n, X, Y, ai[MAX_N], dp[MAX_N][2];
int main()
{
scanf("%d%d%d", &n, &X, &Y);
for (int i = 1; i <= n; i++)
scanf("%d", &ai[i]);
if (n == 1)
printf("%d\n", abs(ai[1] - Y));
else
printf("%d\n... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "-funroll-loops", "-fdelete-null-pointer-checks")
#pragma GCC target("ssse3", "sse3", "sse2", "sse", "avx2", "avx")
using namespace std;
char buf[(1 << 21) + 5], *p1 = buf, *p2 = buf;
inline int qread() {
register char c =
(p1 == p2 && (p2 = (p1 = buf) + fr... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int sol, N;
scanf("%d", &N);
sol = N;
int b[N], a[N];
bool check[N];
for (int i = 0; i < N; i++) {
scanf("%d %d", b + i, a + i);
check[i] = false;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (b[i] == a[j] a... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int main() {
int n;
cin >> n;
vector<int> v;
for (int i = 0, _e(n); i < _e; i++) {
int x;
cin >> x;
v.push_back(x);
}
int s = v.size();
bool innerred;
if (s % 2 == 0)
innerred = false;
else
innerred = true;
... | 2 |
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,dp[100001],a[100001],b;
int main() {
cin >> n >> m;
for(int i=1; i<=m; i++) {
cin >> b;
a[b]=1;
}
dp[0]=1;
for(int i=1; i<=n; i++) {
if(a[i-1]==0) {
dp[i]+=dp[i-1];
}
if(a[i-2]==0) {
dp[i]+=dp[i-2];
}
d... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
int n;
vector<int> a, b;
long long solve(int k) {
vector<vector<int>> t(1);
for (int i : b) {
if (t.back().size() == k) t.push_back(vector<int>());
t.back().push_back(i);
}
long long an... | 2 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdio>
#include<cassert>
#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 MOD 1000000009
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Coor;
//
typedef vec... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
const int N = 0;
int main() {
string s;
cin >> s;
bool ok = false;
string command = "HQ9";
for (int i = 0; i < int(s.size()); ++i)
if (command.find(s[i]) != string::npos) ok = true;
puts(ok ? "YES" : "NO");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string a, b;
cin >> n >> a >> b;
int count = 0;
for (int i = 0; i < n;) {
if (a[i] != b[i]) {
if (a[i] == b[i + 1] && a[i + 1] == b[i]) {
i += 2;
} else {
i++;
}
count++;
} else
i++;
}
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e2 + 5;
int read() {
int s = 0;
char c = getchar(), lc = '+';
while (c < '0' || '9' < c) lc = c, c = getchar();
while ('0' <= c && c <= '9') s = s * 10 + c - '0', c = getchar();
return lc == '-' ? -s : s;
}
void write(int x) {
if (x < 0) {
put... | 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005], brr[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> arr[i] >> brr[i];
int flag = 0, cnt = 0;
for (int i = 0; i < n; ++i) {
flag = 0;
for (int j = 0; j < ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int l[9];
int main() {
int n, a, b, c, r = 1e9;
cin >> n >> a >> b >> c;
for (int i = 0; i < n; i++)
cin >> l[i];
for (int i = 0; i < 1 << n + n; i++) {
int x[4] = {}, u[] = { -1,-1,-1,-1 };
for (int j = 0; j < n; j++)
x[i >> j + j & 3] += l[j], u[i >> j + j ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
... | 1 |
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> II;
int n, m, a[10][10];
int S, T, id;
vector<II> vres;
void add(int x, int y, int z) {
vres.push_back(II(z, ii(x + 1, 200 - y)));
}
bool check(int x, int y, int z) {
for (int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str, str1, arr;
cin >> str >> str1 >> arr;
for (int i = 0; i < arr.size(); i++) {
if (isupper(arr[i])) {
cout << (char)toupper(str1[str.find(tolower(arr[i]))]);
} else if (isdigit(arr[i])) {
cout << arr[i];
} else {
co... | 2 |
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int n;scanf("%d",&n);
for(int i=0;i<n;i++){
int a=-1,b=0,j=0;
for(;j<10;j++){
int c;scanf("%d",&c);
if(a<b&&b<c){
b=c;
}else if(b<a&&a<c){
a=c;
}else if(a<c&&c<b){
a=c;
}else if(b<c&&c<a){
b=c;
}els... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct N {
long long val, lazy;
N() : val(0), lazy(0) {}
};
int n, m;
vector<long long> arr;
vector<N> tree;
long long update(int qs, int qe, int vs, int ve, int node, long long niew) {
int mid;
long long lazy;
lazy = tree[node].lazy;
tree[node].lazy = 0;
tree... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, k, l, m, n, a = INT_MIN, b = 0;
string s = "";
cin >> s;
n = (long long int)s.size();
long long prea[n + 1], preb[n + 1], suff[n + 1];
memset(prea, 0, sizeof(prea));
memset(preb, 0, sizeof(preb));
memset(suff, 0, sizeof(suff));... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
char s[N];
char prev(char c) { return c == 'a' ? 'z' : (char)(c - 1); }
int main() {
scanf("%s", s);
int n = strlen(s);
int left = 0;
while (left + 1 < n && s[left] == 'a') {
left++;
}
int right = left;
while (right + 1 < n && s[ri... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c;
int main() {
while (cin >> a >> b >> c) {
int sum = a * b + b * c + a * c - a - b - c + 1;
cout << sum << endl;
}
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll n;
cin >> n;
vector<ll> A(n+1, 1e9);
for(ll i=0;i<n;i++){
ll x;
cin >> x;
*upper_bound(A.begin(), A.end(), -x) = -x;
}
for(ll i=0;i<=n;i++) if(A[i]==1e9) { cout<<i<<"\n"; break; }
} | 0 |
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <unordered_set>
#include <utility>
#include <vector>
#include <iomanip>
#define int long long
#define rep(i,n) for(int i=0 ; i < (n) ; ++i)
using namespace std;
double kyori(int a,int b,int c,int d,int... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0LL) return b;
if (b == 0LL) return a;
return gcd(b, a % b);
}
const int N = 100005;
pair<long long, long long> A[N];
multiset<int> s;
multiset<int>::iterator it;
void solve() {
int n;
long long x, y;
cin >> n >... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int flag = 0;
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
int mx = a[0];
int min1 = a[0];
for (int i = 0; i < n; i++) {
if (mx < a[i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &FF) {
T RR = 1;
FF = 0;
char CH = getchar();
for (; !isdigit(CH); CH = getchar())
if (CH == '-') RR = -1;
for (; isdigit(CH); CH = getchar()) FF = (FF << 1) + (FF << 3) + (CH ^ 48);
FF *= RR;
}
template <typename T>
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-10
struct Point{
double x,y;
Point(){}
Point(double x,double y) : x(x),y(y) {}
Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
Point operato... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
deque<long long> d;
long long c = 0, f = 0;
map<long long, long long> m;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
m[a]++;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
int an[SIZE], a[SIZE], ma[SIZE], mi[SIZE];
int rmq_ma[20][SIZE], rmq_mi[20][SIZE];
int qq_mi(int L, int R) {
int i = 0;
while ((1 << (i + 1)) <= R - L + 1) i++;
return max(rmq_mi[i][L], rmq_mi[i][R - (1 << i) + 1]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, a, b;
cin >> x >> a >> b;
cout << (abs(x - a) > abs(x - b) ? "B" : "A");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, temp, data[200], hasil = 0;
memset(data, 0, sizeof(data));
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
data[temp]++;
}
for (int i = 1; i <= 100; i++) {
if (data[i] >= 2) hasil += data[i] / 2;
}
printf("%... | 2 |
#include <bits/stdc++.h>
using namespace std;
int v1, v2, t;
int main() {
for (int i = 0; i < 3; i++) {
cin >> t;
v1 += (t << i);
}
for (int i = 0; i < 3; i++) {
cin >> t;
v2 += (t << i);
}
if ((v1 ^ v2) == 7)
cout << "NO";
else
cout << "YES";
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int arr = 200005;
int pow(long long int x, long long int y, long long int p) {
if (y == 0) return 1;
if (y == 1) return x;
x = x % p;
long long int ans = pow(x, y / 2, p) % p;
ans = ans * ans % p;
if (y % 2 == 0)
return ans %... | 5 |
#include <bits/stdc++.h>
const int maxn = 200035;
const int maxm = 400035;
using namespace std;
struct node {
int l, r, val;
node(int a = 0, int b = 0, int c = 0) : l(a), r(b), val(c) {}
bool operator<(node a) const { return l < a.l; }
};
int fa[maxn], son[maxn], top[maxn], siz[maxn];
char opt[13];
int n, m, tim,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s; cin >> s;
cout << (s.find('A') != -1 and s.find('B') != -1 ? "Yes" : "No");
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int nums[100001];
int main() {
int n, x[100001], y[100000], u = 0;
cin >> n;
for (int i = 0; i < n; i++) y[i] = i + 1;
for (int i = 0; i < n; i++) {
cin >> x[i];
nums[x[i]]++;
y[x[i] - 1] = 9999999;
}
sort(y, y + n);
for (int i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void precalc() {}
long long d, n, m;
pair<long long, long long> p[200200];
int next_le[200200];
map<long long, int> mp;
int solve() {
scanf("%I64d%I64d%I64d", &d, &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%I64d%I64d", &p[i].first, &p[i].second);
}
p[m + 1] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long inf = 1LL << 30;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int N = 100100;
int sum1[N], sum2[N], a[N];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k;
scanf("%d%d", &n, &k);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool has[200009];
int left[200009];
int main() {
int Q;
cin >> Q;
for (int q = 0; q < Q; q++) {
int N;
cin >> N;
vector<int> v;
for (int i = 0; i < N; i++) {
int a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
rev... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
k--;
int a[n - 1];
for (int i = 0; i < n - 1; i++) cin >> a[i];
for (int i = 0; i < n - 1;) {
if (i == k) {
cout << "YES";
return 0;
}
i += a[i];
if (i == k) {
cout << "YES";
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5;
long long N, K, arr[100], power_[100], dp[100][100];
bool subset(long long X, long long Y) { return (X & Y) == Y; }
bool ok(long long X) {
long long sum;
for (long long A = 0; A <= N; A++)
for (long long B = 0; B <= K; B++) dp[A][B] = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int mod = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
int a[N], l[N], r[N], d[N], cha[N];
int m, n, k, t;
bool check(int x) {
if (!x) return true;
for (int i = 0; i <= n + 1; i++) cha[i] = 0;
int g = a[x];
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, v[500010], bit[500010];
pair<int, int> tree[4 * 500010];
vector<pair<int, int> > val;
void upd(int nod, int a, int b, int i, int x) {
if (a == b) {
tree[nod] = pair<int, int>(x, i);
return;
}
if (i <= ((a + b) / 2))
upd((2 * nod), a, ((a + b) / 2), ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> emp;
int mas[1001] = {0};
int otv[21][21];
int main() {
int n, a, k[4] = {0}, s = 1;
cin >> n;
for (int i = 0; i < n * n; ++i) {
cin >> a;
mas[a]++;
}
for (int i = 1; i <= 1000; ++i) k[mas[i] % 4]++;
if (n % 2 == 0) {
if (k[1] || k[2] || ... | 3 |
#include <bits/stdc++.h>
int x = 0, y = 0, pos[101][2] = {0};
bool judge(int px, int py) {
if (x == 0 && y != 0)
if (px == 0 && py % y == 0 && py / y >= 0) {
return true;
} else {
return false;
}
if (y == 0 && x != 0)
if (py == 0 && px % x == 0 && px / x >= 0) {
return true;
} ... | 3 |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define N 100010
int n;
int a[N];
void end(int x)
{
if (x == 1) puts ("First");
else puts ("Second");
exit(0);
}
int gcd(int x, int y)
{
while(x)
{
int z = x;
x = y % x;
y = z;
}
return y;
}
int main()
{
cin >> n;
for (int i = 0; i < n... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool roads[405][405];
int bfs(int n, bool road_type) {
queue<int> towns;
towns.push(1);
bool visited[405];
int road_length[405];
for (int i = 1; i <= n; i++) {
visited[i] = false;
road_length[i] = -1;
}
road_length[1] = 0;
visited[1] = true;
while ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename numType>
inline bool updateMax(numType& old, const numType& test) {
if (old < test) {
old = test;
return true;
}
return false;
}
long long MOD;
vector<long long> linearReccurence(const vector<long long>& ks, long long m) {
const int n = ks... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20 + 2;
char pic[maxn][maxn];
int vis[2 * maxn][2 * maxn][2 * maxn][2 * maxn];
int n, m;
int flag;
int solve(int al, int ar, int dl, int dr) {
if (al > ar || dl > dr) return 0;
if (vis[al][ar][dl][dr] != -1) return vis[al][ar][dl][dr];
set<int> st;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, a, t;
cin >> n;
long long ans = 0;
for (long long i = 0; i < n; i++) {
cin >> k >> a;
if (a > 1) {
while (a > 1) {
t = a / 4;
if (a % 4 != 0) t++;
k++;
a = t;
}
ans = max(ans, k);... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k;
for (int i = 1; i < 1000; ++i) {
if (i * (i - 1) / 2 > n) {
k = i - 1;
break;
}
}
vector<vector<int> > data(k + 1, vector<int>(k + 1, 0));
vector<set<int> > ans(k + 1);
int index = 1;
for (int i = 1;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, x, a, b, r, t, d, z, m, c, f;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &n, &x, &a, &b);
f = 0;
d = abs(a - b);
r = max(a, b);
m = min(a, b);
if (d + 1 == n)
printf("%d\n", d);
else {
for (i =... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
string s[402];
long long dp[404][404][8];
long long dx[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long dy[] = {1, 1, 0, -1, -1, -1, 0, 1};
long long check(long long l, long long r) {
if (l < 1 || l > n || r < 1 || r > m) return 0;
if (s[l][r] == '1') return 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1005;
bool bad[maxn];
vector<int> blocked;
vector<int> g[maxn];
bool seen[maxn];
int deg[maxn];
vector<int> good;
int n, m, k;
bool can(double mid) {
memset(bad, 0, sizeof(bad));
memset(deg, 0, sizeof(deg));
memset(seen, 0, sizeof(seen));
queu... | 4 |
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=400005;
int n,m,i,j,k,head[N],adj[N],nxt[N],col[N],num,num1,num2;
long long ans;
void dfs(int x)
{
++k;
for(int y=head[x];y;y=nxt[y])
if(col[adj[y]]==col[x])
j=0;
else if(col[adj[y]]==0)
{
col[adj[y]]=-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
int64_t x,y;
x=0;
for(int i=1;i<n+1;i++){
y=n/i;
x+=(i*y*(y+1))/2;
}
cout<<x<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
long long int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return (temp * temp);
else {
if (y > 0)
return (((x * temp) % 1000000007) * temp);
else
return (temp *... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
int x[100050],ans=inf;
int main() {
int n,k;
cin >> n >> k;
for (int i=1;i<=n;i++) cin >> x[i];
for (int i=1;i<=n-k+1;i++) {
int dis = min(abs(x[i]),abs(x[i+k-1])) + x[i+k-1] - x[i];
if (dis<ans) ans = dis;
}
cout << a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, last, c;
int a[365];
int main() {
cin >> n >> k >> c;
for (int i = 0; i < c; i++) cin >> a[i];
last = 0;
int sum = 0;
for (int i = 0; i < c; i++) {
while (a[i] - last > k) {
last += k;
sum++;
}
last = a[i];
sum++;
}
while ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
long int maximum = -20000009;
int mass[20005];
int summa = 0;
int k = 0;
for (int i = 0; i < n; i++) scanf("%d", &mass[i]);
for (int i = 3; i < n; i++) {
if (n % i == 0) {
for (int k = 0; k < n / i; k++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
char grid[MAXN][MAXN];
int t, n, m, k, l;
inline void solve() {
int re1 = 0, re2 = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m;) {
if (j + 1 <= m && grid[i][j] == '.' && grid[i][j + 1] == '.') {
re2++;
j +... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(6);
for(int i=0;i<6;i++){
cin >>a.at(i);
}
int s=0;
for(int i=0;i<6;i++){
for(int j=0;j<i;j++){
if(a.at(i)==a.at(j))s++;
}
}
if(s==3)cout<<"NO"<<endl;
else cout<<"YES"<<endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{ int i, j, n, m, k;
cin>>n>>m>>k;
for(i=0; i<=n; i++)
for(j= 0 ; j<=m ;j++)
if(n*j+m*i-2*i*j==k) {cout<<"Yes"<<endl;return 0;}
cout<<"No"<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
} E[1500500], Q[1500500];
map<node, int> id;
int ans[1500500][4], c[1500500][2], fa[1500500], p[1500500], rev[1500500],
mx[1500500], val[1500500], q[1500500];
int t, tot, n, m, u, v, cnt2;
int read() {
int x = 0, f = 1;
char ch = getchar();... | 5 |
#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;
string n;
int solve(){
int res=0,memo[12][12];
vector <int> a,b,imemo[12][12];
memset(memo,-1,sizeof(memo));
a.push_back(n[0]-'0'),a.push_back(n[0]-'0'),b.push_back(0);
for(int i=2;i<n.size();i+=2) a.push_back((a.back()+n[i]-'0')%11),a.push_back(a.back());
for(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, q[505];
int x;
int main() {
int i;
cin >> n >> x;
for (i = 0; i < n; i++) cin >> q[i];
sort(q, q + n);
for (i = 0; i < n; i++)
if (q[i] >= x) break;
int ans = 1000;
if (i >= n) {
cout << n + 1 << endl;
return 0;
}
int y = 0;
if (q[i] !... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
long long f(long long a, long long b) {
long long s = b * (b - 1) / 2;
s %= mod;
long long q = (a * b + 1) % mod;
s = (s * q) % mod;
return s;
}
int main() {
long long sum = 0, a, b;
cin >> a >> b;
for (int i = 1; i <= a... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<vector<int>> dist;
vector<vector<bool>> vacant;
int N;
ll ans = 0;
vector<int> dx = {0,0,1,-1}, dy = {1,-1,0,0};
void dfs(int x, int y) {
for (int i = 0; i <= 3; i++) {
int nx = x+dx[i], ny = y+dy[i];
if (nx <= -1 || nx >= N... | 0 |
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
a=min(a,b) ;
c=min(c,d) ;
cout <<(a+c) ;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
bool found = false;
int shock = (1 << 26) - 1;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
char c;
cin >> c;
string s;
cin >> s;
int k = s.length();
int w = 0;
for (int h = 0; h < k; h++) {
int a... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
a = max((3 * a) / 10, a - ((a * c) / 250));
b = max((3 * b) / 10, b - ((b * d) / 250));
if (a < b) {
cout << "Vasya";
} else if (b < a) {
cout << "Misha";
} else {
cout << "Tie";
}
ret... | 1 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using e... | 0 |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=2e5+5;
char buf[1<<12... | 0 |
#include <bits/stdc++.h>
template <class T>
using min_q = std::priority_queue<T, std::vector<T>, std::greater<T>>;
using namespace std;
const int MOD = 1000000000;
bool isletter(char f) { return f >= 'a' && f <= 'z'; }
template <typename T>
void primefactors(T n) {
while (n % 2 == 0) {
cout << 2 << " ";
n /= ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int fac[1000005];
long long int p(long long int a, long long int n) {
long long int res = 1;
while (n) {
if (n % 2) {
res = ((res % 1000003) * (a % 1000003)) % 1000003;
n--;
} else {
a = ((a % 1000003) * (a % 1000003)) % 1000003;
... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(vr) vr.begin(),vr.end()
const ll N=1e5+10,inf=1e18;
ll dp[N],p[N],n,A,B;
int main()
{
//freopen("ss.inp","r",stdin);
ios::sync_wit... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<double, int> &a, const pair<double, int> &b) {
return a.first * b.second > b.first * a.second;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<double, int>> a;
for (int i = 0; i < n; ++i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int fa[202000];
int findd(int x) {
if (fa[x] == x) return x;
return fa[x] = findd(fa[x]);
}
void make(int x, int y) {
x = findd(x);
y = findd(y);
if (x < y)
fa[x] = y;
else
fa[y] = x;
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.