solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (k == n) {
string r = "";
for (int i = 0; i < n; i++) r += char(i + 'a');
cout << r << endl;
} else if (k > n || (k == 1 && n > 1)) {
cout << "-1" << endl;
} else {
int i = 0;
string r = "";
whil... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[200005];
long long s[200005], dp[200005];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
s[i] = a[i] + s[i - 1];
}
for (int i = 1; i <= n; i++)... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
string buf;
while(getline(cin,buf),buf!=""){
string s=buf;
while(getline(cin,buf),buf!="") s+=buf;
string a;
getline(cin,a);
//cout<<s<<endl<<a<<endl;
int n=a.size();
vector<int> pos[n];
for(int i=0;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int b[50], a[1010];
bool work() {
int i, j, pre = -1, t, k;
a[0] = -1;
for (i = 0; i < n; i++) {
t = -1;
for (j = 0; j < m; j++)
if (j != pre && (b[j] > t || j == a[0] && b[j] == t)) t = b[j], k = j;
if (t <= 0) return false;
pre = a[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9 + 7;
bool Reverse(long long a, long long b) { return a > b; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
cout << ((n + 1) / 2) - 1 << endl;
ret... | 1 |
#include <bits/stdc++.h>
using namespace std;
int T, N, R;
int main() {
scanf("%d", &T);
for (int(_z) = (0); (_z) < (T); ++(_z)) {
scanf("%d %d", &N, &R);
R %= N;
int cum = 0;
for (int(i) = (0); (i) < (N - 1); ++(i)) {
int _a;
scanf("%d", &_a);
cum += _a;
cum %= N;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, j = 0;
cin >> n;
int a[n], b[n];
pair<int, int> s[n];
for (auto &i : s) cin >> i.first, i.second = j++;
sort(s, s + n);
map<int, int> mp;
for (int i = 0; i < n; i++) mp[s[i].second] = i;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
int m, c_matches = 0, c_boxes = 0;
cin >> n >> m;
int arr[m][m];
for (int i = 0; i < m; i++) {
cin >> arr[i][0] >> arr[i][1];
c_boxes += arr[i][0];
c_matches += arr[i][0] * arr[i][1];
}
if (n >= c_boxes) {
cout << c_ma... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2> p) {
cout << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
os << "{";
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> v;
set<int> s;
for (int i = 0; i < n; i = i + 1) {
int x;
int sx = s.size();
cin >> x;
s.insert(x);
if (s.size() == sx + 1) {
if (s.size() <= k)
v.push_back(x);
else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a;
int main() {
while (scanf(" %d", &n) == 1) {
int sum = 0, cnt = 0, minn = 1003;
m = 2 * n - 1;
while (m--) {
scanf(" %d", &a);
if (a < 0) {
cnt++;
a = -a;
}
sum += a;
minn = min(minn, a);
}
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
std::vector<pair<pair<long long, long long>, long long> > dis;
std::vector<pair<long long, long long> > bridge;
long long l[200100], r[200100];
long long t;
long long ans[200100];
bool cmp(pair<pair<long long, long long>, long long> A,
pair<pair<lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> gcd(int a, int b) {
if (b == 0) return make_pair(1, 0);
auto ret = gcd(b, a % b);
return make_pair(ret.second, ret.first - a / b * ret.second);
}
struct Modint {
int val;
Modint(int nval = 0) { val = nval; }
Modint& operator+=(Modint r) {
val ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n1, n2, n3, t1, t2, t3;
scanf("%d %d %d %d %d %d %d", &k, &n1, &n2, &n3, &t1, &t2, &t3);
vector<int> f1(n1, 0);
vector<int> f2(n2, 0);
vector<int> f3(n3, 0);
int ans = 0;
for (int i = 0; i < k; i++) {
int p1 = f1[i % n1] + t1 + t2 + t3;... | 4 |
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
using namespace std;
#defin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int i = 0;
int j = 1;
while (i < n) {
if (a[i] >= j) {
i++;
j++;
} els... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s0 =
"What are you doing at the end of the world? Are you busy? Will you save "
"us?";
string s1 = "What are you doing while sending \"";
string s2 = "\"? Are you busy? Will you send \"";
string s3 = "\"?";
int t0 = (int)s0.size(), t1 = (int)s1.size(), t2 = (... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define V_MAX 15
int d[V_MAX][V_MAX];
int INF = 10000;
int dp[1<<V_MAX][V_MAX];
int V, E;
int solve(int T, int u) {
if(dp[T][u] != -1) return dp[T][u];
int res = INF;
for(int v = 1; v < V; v++)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin >> tc;
while (tc--) {
long long int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
long long ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
ans += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool smaller = 1, bigger = 1;
short int small_index = 0, big_index = 0;
string choices[4];
cin >> choices[0];
choices[0].erase(0, 2);
int biggest = choices[0].size(), smallest = choices[0].size();
for (int i = 1; i < 4; i++) {
cin >> choices[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 100005, mod = 1e9 + 7, inf = 1e9;
int n, q, a;
int t[500005];
int j = (1 << 17);
int lazy[500005];
int tab[nax];
char d;
void init(int x) {
for (int i = 1; x >= i; ++i) {
lazy[i] = -1;
t[i] = 2;
}
}
void go(int node, int co) {
if (co <= 1) {
... | 5 |
#include <iostream>
using namespace std;
int main(void){
string s;
while(cin>>s,s!="0"){
for(int i=0;i<3;++i){
if(i)cin>>s;
int a=0,b=0;
for(int j=1;j<s.size();++j){
if(s[j]=='A') ++a;else ++b;
}
if(a>b) ++a;else ++b;
cout<<a<<" "<<b<<endl;
}
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w, k;
cin >> n >> w;
vector<int> b;
for (int i = 0; i < 2 * n; i++) {
cin >> k;
b.push_back(k);
}
sort(b.begin(), b.end());
int mig = b[0], mib = b[n];
double a, f, d;
a = (double)(2 * min(mib * 0.5, (double)mig) * n +
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
int n;
int aa[200001];
int bb[200001];
pair<int,int> cc[200001];
int ans[200001];
int par[200001];
int ss[200001];
int mi[200001];
int find(int no){
if(p... | 0 |
#include <bits/stdc++.h>
const int MAX = 11;
const double PI = acos(-1);
const double eps = 1e-5;
void FFT(std::complex<double> *a, int length, int type) {
for (int i = 1, j = 0; i < length - 1; ++i) {
for (int s = length; j ^= s >>= 1, ~j & s;)
;
if (i < j) {
std::swap(a[i], a[j]);
}
}
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e6 + 10;
const int mod = 998244353;
const int G = 3;
const int iG = (mod + 1) / 3;
int n, m, a[maxn], b[maxn], tr[maxn];
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar(... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int other;
int other_idx;
bool used;
int id;
edge(int other, int other_idx, int id)
: id(id), other(other), other_idx(other_idx), used(false) {}
};
void dfs_eulerian(vector<vector<edge>>& g, vector<int>& indices,
vector<pair<i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, f = 0;
string d, e;
cin >> a >> d >> e;
b = int(d[0] - '0') * 10;
b += int(d[1] - '0');
c = int(e[0] - '0') * 10;
c += int(e[1] - '0');
for (int i = 0;; i++) {
if (c < 0) {
c = 60 - (0 - c);
b--;
}
if (c % 10... | 1 |
#include<cstdio>
#include<complex>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef complex<double> Point;
const double EPS=1e-9;
int n;
Point p[300];
int f(const Point &c){
int res=0;
rep(i,n) if(abs(p[i]-c)<1+EPS) res++;
return res;
}
int main(){
for(;scanf("%d",&n),n... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define N 111116
int n,q;
vector<long long> a;
long long t[N],ans[N];
long long read(){
long long x=0,f=1;char ch=getchar();
for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
return x*f;
}
int main(){
n=read();q=re... | 0 |
#include "bits/stdc++.h"
#include "math.h"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) ... | 0 |
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
map<char,string> t;
map<string,char> s;
string inp,res,code;
t[65]="00000"; t[66]="00001"; t[67]="00010"; t[68]="00011";
t[69]="00100"; t[70]="00101"; t[71]="00110"; t[72]="00111";
t[73]="01000"; t[74]="01001"; t[75]="01010"... | 0 |
/**
* author: tourist
* created: 30.12.2020 17:45:47
**/
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T inverse(T a, T m) {
T u = 0, v = 1;
while (a != 0) {
T t = m / a;
m -= t * a; swap(a, m);
u -= t * v; swap(u, v);
}
assert(m == 1);
return u;
}
template <typen... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
long long dp[200005];
void solve() {
long long n, mod, sum = 0;
cin >> n >> mod;
dp[1] = 1, sum = 1;
for (long long i = 2; i <= n; i++) {
dp[i] = sum;
long long val = 0;
for (long long l = 1, r; l <= i; l = r + 1) {
r = i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i;
string s;
int main() {
scanf("%d%d", &n, &m);
cin >> s;
int x = s.find('G');
int y = s.find('T');
if (x > y) swap(x, y);
for (i = x; i < y; i = i + m) {
if (s[i] == '#') {
break;
}
}
printf("%s", i == y ? "YES" : "NO");
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> aa, aa2;
long long int ans, p;
long long int i, j, k, n, m, A, N, B, C, arr[1000000], flag[1000000],
maxx[1000000], l, r, x, y, a, b, q;
string s, s2;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
aa[arr[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, k, m;
int a[maxn], hsh[maxn], t[maxn];
struct Num {
int id, w;
bool operator<(const Num b) const { return w < b.w; }
};
struct Heap {
Num a[maxn];
int len;
Heap() {
memset(a, 0, sizeof a);
len = 0;
}
void push(Num x) {
... | 4 |
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
int y, m, d;
int a;
while (scanf("%d%d%d", &y, &m, &d) != EOF){
a = (y * 10000 +m * 100 + d);
if (a < 18680908) {
cout << "pre-meiji" << endl;
continue;
}
if (a < 19120730){
cout << "meiji " << y-1867 << " " << m << " " << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int x, y, z;
pair<int, int> ans;
string a, b, c;
void calc(int x, int y, int z) {
if (x == 0 && z == 0) {
ans.first = 2, ans.second = y;
return ;
}
if (x == 0 && y == 0) {
ans.first = 3, ans.second = z;
return ;
}
if (y == 0 && z == 0) {
ans.first = 1, ans.... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long double EPS = 1e-9L;
const long double MAX_SQR_LEN = 2250000000000.0L;
bool eq(long double x, long double y) { return a... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 3;
int n;
void input() { cin >> n; }
void solve() {
cout << (n / 2 + (n % 2)) * (n / 2) << endl;
for (int i = 1; i <= n / 2; i++)
for (int j = n / 2 + 1; j <= n; j++) cout << i << ' ' << j << endl;
}
int main() {
ios::sync_with_stdio(0), cin.ti... | 5 |
#include<iostream>
#include<string>
using namespace std;
struct NODE { int key; NODE *pa, *ri, *le; };
NODE *NIL, *root;
void insert(int k)
{
NODE *z, *x = root, *y = NIL;
z = new NODE;
z->key = k;
z->le = NIL;
z->ri = NIL;
while (x != NIL)
{
y = x;
if (z->key < x->key)
x = x->le;
else
x = x->ri;... | 0 |
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int N, M;
vector<vector<int> > G;
vector<bool> seen;
bool rec(int v, int p, int s, int t) {
if (v == s && p != -1) return true; // 一周回ってきて s に戻って来たら OK
if (v != s) seen[v] = true;
for (auto nv : G[v]) {
if (nv == p || nv ==... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
const int N = 212345;
int n;
long long int dp[N];
int par[N];
pair<int, int> a[N];
int id[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
dp[i + 1] = llINF;
int c;
scan... | 5 |
#include<bits/stdc++.h>
using namespace std;
const int MX = 105;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, m, a, pr[MX], w, b[MX][MX];
set<int> st[MX];
bool used[MX];
bool dfs(int v){
used[v] = true;
for(int it: st[v]) if((w = pr[it/m]) < 0 || (!used[w] && dfs(w))){
pr[it/m] = v;
return true;
}
return fa... | 0 |
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int N, d, f;
scanf("%d", &N);
d = N / 3;
if (N % 3 > 1) {
d++;
}
f = d / 12;
d = d - f * 12;
printf("%d %d\n", f, d);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[104];
int main() {
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
int n, k;
long long ans = 0;
cin >> n >> k;
for (int j = 1; j <= n; j++) {
cin >> a[j];
}
sort(a + 1, a + n + 1);
int r = n;
int l = n - k;
for (int j = ... | 4 |
#include <bits/stdc++.h>
int main() {
char a[1000002];
int i, x = 0, y = 0, d;
scanf("%s", a);
for (i = 0; i < strlen(a); i++)
if (a[i] == 'x')
x++;
else
y++;
d = x - y;
if (d > 0)
while (d--) printf("x");
else
while (d++) printf("y");
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int t;
cin >> t;
while (t--) {
int result = 0, cntr = 0;
vector<int> v;
cin >> s;
for (int j = 0; j < s.length(); j++) {
if (s[j] == '1') {
cntr++;
} else {
if (cntr) v.push_back(cntr);
cntr ... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s, int i) {
for (int j = 0; j < i / 2 + 1; j++) {
if (s[j] != s[j + i / 2 + 1]) return false;
}
return true;
}
int main() {
string s;
int n;
cin >> n;
cin >> s;
int cnt = 0;
for (int i = s.size() - 1; i >= 0; i--) {
if (i % 2 == 0... | 2 |
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
while(cin>>a>>b)
{
c=a+b;
int k=0;
while(c>0)
{
c/=10;
k++;
}
cout<<k<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
#define MAXN (200010)
int n;
int q[MAXN], t[MAXN], f[MAXN];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; ++ i){
int pi;
scanf("%d", &pi);
q[pi] = i;
}
for(int i = n - 1; i; -- i){
if(!t[i + 1]){
if(q[i] > q[i + 1]){
t[i] = 1;
f[i] = i + 1;
}
else{
cont... | 0 |
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int N, M, b, Exit, mask;
int v[1 << 15];
int ret;
void rec(int digit, int cnt){
if(cnt >= ret) return;
if(digit == Exit || digit == ((~Exit) & mask)){
ret = min( ret, cnt);
return;
} else if(v[digit & mask] <= cnt){
return;
} e... | 0 |
#include <bits/stdc++.h>
int dp[10001];
int main() {
int i, k, n1, n2, n3, t1, t2, t3;
scanf("%d%d%d%d%d%d%d", &k, &n1, &n2, &n3, &t1, &t2, &t3);
for (i = 1; i <= k; i++) {
dp[i] = t1 + t2 + t3;
if (i >= n1)
dp[i] = ((dp[i]) > (dp[i - n1] + t1) ? (dp[i]) : (dp[i - n1] + t1));
if (i >= n2)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<char> animals(n);
int tigers = 0;
for (int i = 0; i < n; i++) {
cin >> animals[i];
if (animals[i] == 'T') tigers++;
}
int l = 0;
int r = tigers;
int max = 0;
for (l = 0; l < n; l++) {
int inzone = 0;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> a(n + 1), dp(n + 1, 1);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = n; i >= 1; i--) {
int mx ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10000000;
int tmp[30], cnt;
bool check(int x) {
cnt = 0;
int y = x;
while (y) tmp[cnt++] = y % 10, y /= 10;
if (cnt == 1) return 1;
if (tmp[0] == tmp[1]) return 0;
if (tmp[0] > tmp[1]) {
for (int i = 0; i < cnt - 1; i += 2)
if (tmp[i +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[501][501];
long long ar[501][2];
int n, k;
int rek(int cur, int leftRed) {
if (cur == -1) return leftRed == 0;
if (dp[cur][leftRed] == -1) {
dp[cur][leftRed] = rek(cur - 1, ((leftRed - ar[cur][0]) % k + k) % k);
for (int ctr1 = 0; ctr1 <= k; ++ctr1) {
... | 5 |
#include <iostream>
using namespace std;
#define N 16
int ans[N];
int cur[N];
int anspos[N];
int movepos[4] = {-4, 1, 4, -1};
int checkAns() {
for (int i = 0; i < N; i++) {
if (ans[i] != cur[i]) return 0;
}
return 1;
}
int calcEst() {
int total = 0, t;
for (int i = 0; i < N; i++) {
if (cur[i]==0)c... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005], dir[100005], vec;
int vis1[100005], vis2[100005], vis3[100005], fl = 0;
void dfs1(int u) {
vis1[u] = 1;
vec.push_back(u);
for (int i = (int)0; i <= (int)adj[u].size() - 1; i++) {
if (!vis1[adj[u][i]]) dfs1(adj[u][i]);
}
}
void dfs2(int u... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
int p = n / 2;
int t = 0;
for (int i = 1; i <= p; i++) {
if (t)
printf("aa");
else
printf("bb");
t = 1 - t;
}
if (n % 2) {
if (t)
printf("a");
else
printf("b");
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10;
const long long INF = 1e18;
long long a, b, c, d, dp[maxn], sum[maxn], ans = 0;
long long f(long long z) {
if (z > (b + c)) return 0;
if ((a + b) > z) return 0;
return min(z - b, b) - max(z - c, a) + 1;
}
signed main() {
ios_base::sy... | 3 |
#include <bits/stdc++.h>
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T lcm(T a, T b) {
return a / __gcd(a, b) * b;
}
template <class T>
T minimize(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T maximize(T &a, T b) {
if (a < b) {
a = b;... | 4 |
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;
int main(){
long int N;
cin >> N;
for(int n=1; n<3501; n++){
for(int h=1; h<3501; h++){
long int num = N * h * n;
long int den = 4*h*n - N*(n+h);
if (den > 0 && num % den == 0){
cout << n <<" "<< h <<" " << num / den <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long int inf = -1e18;
const int MOD = 1e9 + 103;
int h[26];
int p[1505];
map<long long int, bool> mp;
long long int power(long long int x, long long int y) {
long long int ans = 1;
x %= MOD;
while (y) {
if (y & 1) ans = (ans * x) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<long> v[200000];
int n, i, j, k, l, r, m;
long a;
int main() {
cin >> n;
cin >> a;
v[0].push_back(a);
k = 0;
for (i = 1; i < n; i++) {
cin >> a;
if (v[0][v[0].size() - 1] < a) {
v[0].push_back(a);
;
} else {
r = k;
l = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int to[2000000], h[2000000], nex[2000000];
int top, x, y, u, v, n, fu[500000][30], dep[2000000];
int num[2000000], lg[2000000], m;
void add(int p, int q) {
top++;
to[top] = q;
nex[top] = h[p];
h[p] = top;
}
void dfs(int x, int fa) {
dep[x] = dep[fa] + 1;
fu[x][0... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n = 8, YES = 0;
char a[10][10][10];
int was[10][10][10];
void dfs(int x, int y, int z) {
++was[x][y][z];
if (z == 8) {
++YES;
return;
}
if (z < n + 1) {
if (a[x][y][z + 1] == '.' && !was[x][y][z + 1]) dfs(x, y, z + 1);
if (y - 1 >= 0 && a[x][y - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 555;
int n, d[N], a[N];
struct udsu {
private:
vector<unsigned> D;
void __init__(size_t n) {
D.resize(n + 1);
for (unsigned i = 0; i <= n; i++) D[i] = i;
}
int __find__(unsigned x) {
if (x >= D.size()) resize(x);
return D[x] = (D[x] ==... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> g[2 * 100011];
bool p = 0;
bool mark[100011 * 2];
long long x = 0, y = 0;
void dfs(long long v) {
if (mark[v]) return;
mark[v] = 1;
y += g[v].size();
if (g[v].size() != 2) p = 1;
for (long long i = 0; i < g[v].size(); i++) {
long long u = g[v... | 5 |
#include <bits/stdc++.h>
using namespace std;
int testnum;
vector<long long> nums;
int cnt;
void preprocess() {}
int a[3][3];
int getnumber(int i, int j) {
int r = a[i][j];
if (i - 1 >= 0) r += a[i - 1][j];
if (j - 1 >= 0) r += a[i][j - 1];
if (i + 1 < 3) r += a[i + 1][j];
if (j + 1 < 3) r += a[i][j + 1];
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[400005], id[400005];
bool cmp(long long x, long long y) { return a[x] < a[y]; }
int main() {
long long n, i, x;
cin >> n;
for (i = 0; i < n; i++) {
id[i] = i;
cin >> a[i];
}
sort(id, id + n, cmp);
long long last = -1;
for (i = 0; i < n; i++... | 3 |
#include<bits/stdc++.h>
using namespace std;
bool used[2000001];
int n,h,w,x;
int main(){
cin>>n>>h>>w;
for(int i=0;i<n;i++){
cin>>x;
if(i%2==0)for(int j=(w)*(i)+x;j<(w)*(i)+x+w;j++){
if(j>=0&&j<=w*n)used[j]=1;
}
else for(int j=w*(i)-x;j<w*(i)-x+w;j++){
if(j>=0&&j<=w*n)used[j]=1;
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[150005], b[150005], c[150005], m = 0;
int snt[44722 + 1];
void sangnt() {
long i, j;
for (i = 1; i <= 44722; i++) snt[i] = 1;
snt[1] = 0;
i = 2;
while (i <= sqrt(44722)) {
while (snt[i] == 0) i++;
for (j = 2; j <= 44722 / i; j++) snt[i * j] = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N];
int n;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
cin >> n;
for (int i = (0); i <= ((n)-1); i += (+1)) {
cin >> a[i];
}
a[n] = 2e9;
sort(a, a + n);
int ans = 0;
for (int ... | 3 |
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
int a[N];
int gcd(int x,int y){
if (!y) return x;
else return gcd(y,x%y);
}
bool solve(){
int yi=0,er=0;
for (int i=1;i<=n;i++){
if (a[i]==1) yi++;
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
vector<char> v;
int n, count = 0;
char cur;
cin >> n;
while (n--) {
cin >> cur;
v.push_back(cur);
}
for (int i = 0; i < v.size() - 1; i++) {
if (v[i] == v[i + 1]) {
v.erase(v.begin() + 1);
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<vector<int> > gr;
int an[100010][20], tin[100010], tout[100010], t;
int dep[100010], sz[100010];
void dfs(int x, int par, int d) {
tin[x] = t++;
dep[x] = d;
sz[x] = 1;
an[x][0] = par;
for (int i = 1; i < 20; ++i) {
an[x][i] = an[an[x][i - 1]][... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x = 0, y = 0;
int n;
cin >> n;
string s;
cin >> s;
for (char c : s) {
if (c == 'U') y--;
if (c == 'D') y++;
if (c == 'L') x--;
if (c == 'R') x++;
}
cout << n - abs(x) - abs(y);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long prev = 0;
long long cur = 0;
for (int i = 1; i <= n; i++) {
long long a;
cin >> a;
if (i == 1) {
prev = a;
cur = 1;
continue;
}
if (a - prev > k) {
cur = 1;
} els... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 1e5;
const int INF = 0x7fffffff;
const int mod = 1e9 + 7;
const double eps = 1e-7;
const double Pi = acos(-1.0);
inline int read_int() {
char c;
int ret = 0, sgn = 1;
do {
c = getchar();
} while ((c < '0' || c > '9') && c... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int mod = 1e9 + 7;
int n, m, k, ans, x, y;
vector<pair<int, pair<int, int> > > all;
bool used[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
all.push_ba... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n -= 2;
cout << (n / 2 + (n % 2 > 0));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool se[105][105];
int main() {
ios_base::sync_with_stdio(0);
long long n, k, i, j, l, z, sum = 0, yl, yr, ise, min1;
cin >> n >> k;
while (n--) {
cin >> z;
yl = 69696;
ise = 69696;
yr = 69696;
min1 = 99999999;
for (i = 1; i <= k; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, c, y, v, maxi;
scanf("%I64d", &x);
scanf("%I64d", &y);
scanf("%I64d", &c);
scanf("%I64d", &v);
maxi = max(abs(x - c), abs(y - v));
printf("%I64d", maxi);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
double sum, pd;
int a, b, c, num;
int main() {
cin >> a >> b;
for (int i = 1; i <= a; i++) {
cin >> c;
sum += c;
}
pd = b - 0.5;
if (sum / a >= pd) {
cout << "0";
return 0;
}
while (1) {
num++;
if ((sum + b * num) / (a + num) >= pd) {
... | 1 |
#include<iostream>
int main() {
int x, t;
std::cin >> x >> t;
std::cout << (x > t ? x - t : 0) << std::endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
template <class T>
inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return fa... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int loga = 20;
const int off = 1 << loga;
int n, t;
int niz[maxn];
int tour[off * 2];
map<int, vector<int> > m;
vector<int> ac;
int gcd(int x, int y) {
if (y == 0)
return x;
else
return gcd(y, x % y);
}
int query(int a, int b, in... | 6 |
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
int main() {
string s; cin >> s;
if (s.size() < 26) {
for (char c = 'a'; c <= 'z'; c++) {
if (s.find(c) == -1) {
cout << s << c << endl;
return 0;
}
}
}
else {
set<char>x;
while (!s.empty()) {
char ... | 0 |
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
int main(void)
{
for(;;){
int n,pw;
cin >> n;
if(!n) return 0;
cin >> pw;
set<long double> wss;
wss.insert(0... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long s, x;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> s >> x;
if (x > s || (x % 2 != s % 2)) {
cout << 0;
return 0;
}
long long an = (s - x) / 2;
long long coef = 1;
for (int i = 0; i < 50;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N, X;
vector<int> R;
char S[105];
int main() {
scanf("%d", &N);
scanf("%s", S);
S[N++] = 'W';
for (int i = 0; i < N; i++) {
if (S[i] == 'B')
X++;
else if (X)
R.push_back(X), X = 0;
}
printf("%d\n", R.size());
for (int i = 0; i < R.size(... | 1 |
#include <bits/stdc++.h>
void search(int k, int n, int &x, int &y) {
int c, tmp;
if (k == 0) {
x = 0;
y = 0;
return;
}
c = 0;
for (int i = 0; i < k - 1; i++) c = 4 * c + 3;
tmp = (1 << k - 1) - 1;
if (n <= c) {
search(k - 1, n, x, y);
x ^= y, y ^= x, x ^= y;
} else if (n <= 2 * c + 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
struct Edge {
int y, ne;
};
int n, m, num, ans;
int x[N], y[N], dis[N];
Edge e[N];
int last[N];
pair<int, int> f[N][10], g[N][10];
pair<int, int> a1, a2;
queue<int> Q;
void add(int x, int y) {
e[++num] = (Edge){y, last[x]};
last[x] = num;
}
void bf... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 1000000007;
int n, m;
int sz;
string s[2];
vector<int> gr[200000];
int num[2][300002];
bool used[300002];
int dist[300002];
int lca[300002][30];
int l = 20;
int timer;
int tin[300002];
int tout[300002];
int cnt[300002];
int ccnt = 1;
void dfs(int v, i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, x, z, s, d, t, ans, a[500007];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for (i = 0; i < 2 * k; i++) {
cin >> x >> z;
}
string s;
for (i = 0; i < n - 1; i++) {
s += 'U';
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int arr[1005], val[1005];
long double dp[1005];
int par[1005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, K;
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> arr[i] >> val[i];
}
long double l = 0, r = 1e9, ans = 0;
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long inline gcd(long long x, long long y) {
return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long inline lcm(long long a, long long b) {
return ((long long)abs((a / gcd(a, b)) * b));
}
double inline cartesian_dist(double x1, double y1, double x2, double y2) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void findMin(int sum) {
int a = -1, b = 0;
for (b = sum / 7; b >= 0; b--) {
int rem = sum - b * 7;
if (rem % 4 == 0) {
a = rem / 4;
break;
}
}
if (a < 0) {
printf("-1\n");
return;
}
for (int i = 0; i < a; i++) printf("4");
for (... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.