solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
map<int, vector<int> > even, odd;
int a[N], used[N];
int e = 2, o = 1;
bool flag = true;
int get_even() {
while (used[e]) {
e += 2;
if (e >= N) return -1;
}
used[e] = 1;
if (e > m) flag = false;
return e;
}
int get_odd() {... | 5 |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x;
while(cin >> x) {
double y;
y=4.9*((x/9.8)*(x/9.8));
cout << ceil(y/5)+1 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector <int> a(n);
for(int i=0;i<n;i++) a[i]=i+1;
do{
for(int i=0;i<n;i++){
if(i) cout<<" ";
cout<<a[i];
}
cout<<endl;
}while(next_permutation(a.begin(),a.end()));
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, ans, vis[200005], odd, even;
vector<long long> adj[100005];
void dfs(long long x) {
vis[x] % 2 == 0 ? even++ : odd++;
long long sz = adj[x].size();
for (int i = 0; i < sz; i++) {
long long y = adj[x][i];
if (vis[y] == -1) {
vis[y] = (v... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, d, b, l, r, need, ans1, ans2;
long long a[500011], n1[500011], n2[500011];
int main() {
scanf("%lld%lld%lld", &n, &d, &b);
long long re = (n >> 1) * b;
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++)
n1[i] = min(a[i],... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr(i, a, b) for (int i = (int)(a - 1); i >= b; i--)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb(s) push_back(s)
#define all(x... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int in[maxn], in1[maxn];
int dp[maxn];
int dp1[maxn];
int dp2[maxn];
int s[maxn];
int vis[maxn];
int dp3[maxn];
vector<int> g[maxn];
int a[maxn];
int k;
int flag;
void dfs(int u, int pa) {
int p = g[u].size();
dp1[u] = 1;
vis[u] = 1;
for (in... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct DSU {
int count;
vector<int> vs, ss;
DSU(int n) : count(n), vs(n, -1), ss(n, 1) {
for (int i = 0; i < n; i++) vs[i] = i;
}
int get(int x) { return x == vs[x] ? x : vs[x] = get(vs[x]); }
void unite(int a, int b) {
a = get(a);
b = get(b);
if... | 1 |
#include <bits/stdc++.h>
int main() {
int n, *a, count = 0, min = 2000000000;
scanf("%i", &n);
a = new int[n];
for (int i = 0; i < n; ++i) {
scanf("%i", &a[i]);
}
std::sort(a, a + n);
for (int i = 0; i < n - 1; ++i) {
if (min > abs(a[i] - a[i + 1])) {
min = abs(a[i] - a[i + 1]);
count ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, ok, nn, mm, kk;
queue<pair<pair<int, int>, int> > q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
pair<int, int> mk[m + 1][k + 1], nk[n + 1][k + 1], nm[n + 1][m + 1],
qmk[m + 1][k + 1], qnk[n + 1][k + 1... | 6 |
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;
#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
typedef long long llong;
typedef vector<int> VI;
typ... | 0 |
#include<iostream>
using namespace std;
int main()
{
int x,y,z; cin>>x>>y>>z;
cout<<z<<' '<<x<<' '<<y;
cout<<'\n';
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<P,ll>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexp... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > ans[111];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) ans[i].push_back(make_pair(i, i));
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
ans[x].push_back(make_pair(n + i, x));
ans[y... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
if(a%2==1||b%2==1||c%2==1)
{
printf("0\n");
return 0;
}
for(int i=1;i<=1000000;i++)
{
int na=(b+c)/2,nb=(a+c)/2,nc=(b+c)/2;
if(na%2==1||nb%2==1||nc%2==1)
{
printf("%d\n",i);
return 0;
}
a=na;
b... | 0 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(++it, args...);
}
const long long int nax = 1e5 + 5;
long long int n, m, ans;
vector<long l... | 3 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
constexpr long long int M = 1e9 + 7;
long long int inv(long long int a, long long int b = M) {
return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
long long int f[200010], fi[200010];
l... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N, K, S, i, ans=0; cin >> N >> K >> S;
for(i=0; i<K; i++){ cout << S << " "; }
if(S<=2){ for(i=K; i<N; i++){ cout << S+1 << " "; } }
else{ for(i=K; i<N; i++){ cout << S-1 << " "; } }
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e5+23;
int a[maxn];
const int mod = 1e9+7;
int n,k;
int fac[maxn],inv[maxn];
int qpow(int a,int b)
{
int ans=1;
while(b){
if(b&1) ans=1ll*ans*a%mod;
b>>=1;
a=1ll*a*a%mod;
... | 0 |
// Ref : https://book.mynavi.jp/ec/products/detail/id=35408
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int n, pos;
vector<int> pre, in, post;
void rec(int l, int r) {
if (l >= r) return;
int root = pre[pos++];
int m = distance(in.begin(), find(in.begin(), in.... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(10);
int n;
while (cin >> n, n) {
vector<string> f(n);
vector<int> w(n), s(n), ord(n);
for (int i = 0; i < n... | 0 |
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long read(){
long long xx=0,flagg=1;
char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')
ch=getchar();
if(ch=='-'){
flagg=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
xx=xx*10+ch-'0';
... | 0 |
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main() {
string t;
while(getline(cin,t)) {
for(int i = 0; i < 26; i++) {
for(int j = 0; j < t.size(); j++) {
if(t[j] == ' ' || t[j] == '.') continue;
t[j] += 1;
if(t[j] > 'z') t[j] -= 26;
}
if(t.find("the") != string:... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N , K;
cin >> N >> K;
if(K == 1)
cout << 0;
else
cout << N-K;
} | 0 |
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
using namespace std;
bool is_sorted(ll a[],ll n)
{
for(ll i=1;i<n;i++)
if(a[i]<a[i-1])
return false;
return true;
}
int main()
{
#ifndef ONLINE_JUDGE
//for getting inp... | 4 |
#include <bits/stdc++.h>
using namespace std;
int prime[103];
int dp[300003][103];
long long dfs(long long n, int m) {
if (prime[0] == 1 || n == 0) return 0;
if (n < 300001 && dp[n][m] > -1) return dp[n][m];
long long ans = 0;
if (m == 0)
ans = n;
else
ans = dfs(n, m - 1) - dfs(n / prime[m - 1], m - 1... | 5 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 310;
int n, tot;
vector<int> edges[MAX];
vector<int> path[MAX][MAX];
vector<int> ans;
bool vis[MAX];
vector<int> p;
int root;
void get_tot(int v) {
vis[v] = 1;
bool is = 1;
for (int u : edges[v]) {
if (!vis[u]) {
get_tot(u);
is = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
char a[300];
int main() {
scanf("%s", a);
int n;
n = strlen(a);
int i;
int flag = 0;
int sum = 0;
for (i = 0; i < n; i++) {
if (a[0] == '@' || a[n - 1] == '@' || (a[i + 1] == '@' && a[i] == '@') ||
(a[i + 2] == '@' && a[i] == '@'))
flag = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[2021];
bool tog1, tog2;
int t1, t2;
int main() {
cin >> s;
t2 = strlen(s);
for (int i = 0; s[i]; i++) {
if (i && s[i] == s[i - 1] && s[i] == '.') {
puts("NO");
return 0;
}
if (i && s[i] == s[i - 1] && s[i] == '/') {
puts("NO");
... | 1 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("frac1.in");
ofstream fout("frac1.out");
class compare : public std::binary_function<double, double, bool> {
public:
compare(double arg = 1e-7) : e(arg) {}
bool operator()(const double &left, const double &right) const {
return (abs(left - right) > e) ... | 3 |
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rrep(i, a, b) for(ll i = a; i >= b; --i)
#define p... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool in[2001][2001];
int x[3000], y[3000], n, i, j, ans;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", x + i, y + i);
in[x[i] + 1000][y[i] + 1000] = true;
}
for (i = 0; i < n; i++)
for (j = 0; j < i; j++)
if (~(x[i] ^ x[j]) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];
pair<int, int> b[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i].first;
}
for (int i = 0; i < n; i++) {
cin >> b[i].second;
}
sort(b, b + n);
for (int i = 0; i < n; i++) cout << b... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
bool isprime(long long n) {
if (n == 2) {
return true;
}
if (n % 2 == 0) {
return false;
}
for (long long i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) {
return false;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
long long ans = 0;
int arr[1000005];
pair<int, int> srt[1000005];
set<int> st;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> arr[i];
ans -= arr[i];
srt[i] = {arr[i], i};
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T rin(T &r) {
int b = 1, c = getchar();
r = 0;
while (c < '0' || '9' < c) b = c == '-' ? -1 : b, c = getchar();
while ('0' <= c && c <= '9')
r = (r << 1) + (r << 3) + (c ^ '0'), c = getchar();
return r *= b;
}
template <class T>
inlin... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.14159265359;
template <typename T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
return x * x;
}
const int maxn = 405 * 4;
char isV[maxn];
vector<int> g[maxn];
vector<int> gt[maxn];
int enc(int v, int vo, int neg) { re... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, t, a[1005], maxn = -99999999;
string s[1005];
map<string, int> k, kp;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i] >> a[i];
k[s[i]] += a[i];
}
for (int i = 0; i < n; i++) {
maxn = max(maxn, k[s[i]]);
}
for (int i = 0; i < n... | 1 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[1005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].first);
a[i].second = i;
}
sort(a, a + n, greater<pair<int, int>>());
int res = 0;
for (int i = 0; i < n; i++) res += i * a[i].first + 1;
pri... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 2000000000, x, y;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
ans = min(ans, y - x + 1);
}
cout << ans << endl;
for (int i = 0; i < n; i++) cout << i % ans << " ";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t;
cin >> n;
t = sqrt(n);
long long m = n;
for (int i = 2; i < t + 1; i++) {
if (n % i == 0) {
m = i;
break;
}
}
if (m != n)
cout << (n - m) / 2 + 1;
else
cout << n / m;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
long long read() {
char ch = getchar();
long long x = 0;
int op = 1;
for (; !isdig... | 2 |
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int n;
double r[505];
double p[505];
int main(void)
{
cin >> n;
for(int i = 1; i <= n; i++) cin >> r[i];
p[1] = r[1];
for(int i = 2; i <= n; i++){
p[i] = r[i];
for(int j = 1; j < i; j++){
double r1 = r[i], r2 = r[j];... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const long long base = 311;
long long gcd(long long a, long long b) {
while (b != 0) {
long long r = a % b;
a = b;
b = r;
}
return a;
}
long long lcm(long long a, long long b) { return (a * b) / gc... | 1 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using vi = vector<lli>;
using vvi = vector<vi>;
using pii = tuple<lli, lli>;
using vii = vector<pii>;
using vvii = vector<vii>;
string TYPE(const int*) { return "%d"; }
string TYPE(const lli*) { return "%lld"; }
string ... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct UF {
int par[3005], rank[3005];
int cost[3005];
void init(int n) {
for (int i = 0; i < n; i++) {
par[i] = i;
rank[i] = cost[i] = 0;
}
}
void add(int k, int x) { cost[k] = x; }
int find(int x) {
if (x == par[x]) return x;
return... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a;
string b;
string c;
int ilea[550], ileb[550], ilec[550];
int wyn1, wyn2;
int ilez[550];
int aktu2;
int main() {
cin >> a;
cin >> b;
cin >> c;
for (int i = 0; i < a.size(); i++) {
ilea[a[i]]++;
}
for (int i = 0; i < b.size(); i++) {
ileb[b[i]]++... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool checkbitt(long long int num, int pos);
long long int setbitt(long long int num, long long int pos);
long long int resetbitt(long long int num, int pos);
void read(int &a) { scanf("%d", &a); }
void read(int &a, int &b) { scanf("%d %d", &a, &b); }
void read(int &a, int &... | 3 |
#include <iostream>
using namespace std;
int main(){
int N, X, T;
cin >> N >> X >> T;
cout << (N+X-1)/X*T << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod=1000000007;
int32_t main() {
int n;
cin>>n;
vector<int>a(64,0);
for(int j=0;j<n;j++){
int x;
cin>>x;
bitset<64>c(x);
for(int i=0;i<64;i++)
if(c.test(i))
a[i]++;
}
int ans=0;
int j=1;
for(int i=0;i<6... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int tmp, tp, a, b, u, v, n, m, to[500010], deep[500010], nxt[500010],
hd[500010], fa[100010], tofa[500010], num = -1, cf[500010];
bool tree[500010], vis[100010], flag;
void add(int u, int v) {
nxt[++num] = hd[u], to[num] = v, hd[u] = num;
nxt[++num]... | 6 |
#include <bits/stdc++.h>
using namespace std;
int h = 1e9, e = 1e9, l1 = 1e9, l2 = 1e9, o = 1e9;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'h') {
h = i;
break;
}
}
for (int i = h; i < s.size(); i++) {
if (s[i] == 'e') {
e = i;
break;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[102];
int l[102], r[102];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
long long bsum = 0;
for (int i = 1; i <= m; ++i) {
scanf("%d %d", &l[i], &r[i]);
long long snow = 0;
for (int j = l[i]; j <= r[i]; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 60;
struct Tree {
int val[maxn];
int N;
inline int lowbit(int x) { return x & (-x); }
void init(int n) {
N = n;
for (int i = 1; i <= n; i++) {
val[i] = 0;
}
}
void add(int pos, int v) {
while (pos > 0) {
val[pos... | 5 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, t, K, an, num;
int fa[100010][20], dfn[100010], dep[100010], b[100010], g[100010], F[100010],
f[100010];
vector<int> a[100010], c[100010];
inline int lca(int x, int y) {
if (dep[x] > dep[y]) swap(x, y);
int i;
for (i = 19; i >= 0; i--)
if (d... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, q;
bool f[100005];
bool a[3][100005];
void init() {
cin >> n >> q;
memset(f, 1, sizeof(f));
memset(a, 1, sizeof(a));
}
bool chk(int k) {
if (a[1][k] && a[1][k + 1]) return true;
if (a[2][k] && a[2][k + 1]) return true;
return f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
int T;
T = 1;
while (T--) {
int n, i, j;
cin >> n;
int ar[n + 1], visited[n + 1];
for (i = 1; i <= n; ++i) {
cin >> ar[i];
visited[i] = 0;
}
int ct = 0;
for (i = 1; i <= n; ++i) {... | 2 |
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define all(x) x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define INF L... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010;
int n, m, k, u, v, x, y, t, a, b, ans;
vector<int> vec[26];
string s;
int main() {
ios_b... | 2 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int t, n, lenn;
long long int last(long long int x) {
long long int tr = x;
lenn = 0;
while (x > 0) {
tr = x % 10;
x /= 10;
++lenn;
}
return tr;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
long long in... | 1 |
#include<bits/stdc++.h>
using namespace std;
//BEGIN CUT HERE
template<typename T>
struct BIT2D{
int n,m;
T d;
vector<vector<T> > bit;
//1-indexed
BIT2D():n(-1),m(-1){}
BIT2D(int n_,int m_,T d_):n(n_),m(m_),d(d_),bit(n_+1,vector<T>(m+1,d_)){}
T sum(int i,int j){
T s=d;
for(int x=i;x>0;x-=(x&-x))
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int k;
vector<int> v;
int main() {
cin >> n >> m >> k;
for (long long int i = 1; i * i <= n; i++) {
v.push_back(i);
v.push_back(n / i);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
long long int ans = 0;
for (... | 1 |
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef d... | 0 |
#include <bits/stdc++.h>
int n, m, a, b, h[3001][3001], que[3001], beg, end, nh[3001][3001];
long long ans;
int main() {
int x, y, z;
scanf("%d%d%d%d%d%d%d%d", &n, &m, &a, &b, &h[1][1], &x, &y, &z);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
if (i != n || j != m)
h[i + (j + 1) / (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[100];
vector<pair<int, int> > can[100];
int ones(int mask) {
int ans = 0;
while (mask) {
ans += mask % 2;
mask /= 2;
}
return ans;
}
int memo[1 << 23];
bool vis[1 << 23];
int dp(int u, int mask) {
if (u == 0) return 1;
int &ret = memo[... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int Maxn = 1005;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
int tot = 0;
int evens[5];
memset(evens, 0, sizeof evens);
for (int j = 0; j < s.size(); j++) {
int temp = s[j] - '0';
tot += temp;
if (temp % 2 =... | 1 |
#include <bits/stdc++.h>
const int INF = ~0u >> 2;
int main() {
int n;
scanf("%d", &n);
std::vector<int> c(n);
for (int i = 0; i < n; ++i) {
scanf("%d", &c[i]);
}
int ans = INF;
for (int i = 1; i < n; ++i) {
for (int j = i; j < n; ++j) {
int x = c[i - 1] - 1;
int y = 0;
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s, p, q;
string a[210];
int n, i, d[210];
int RS;
int nr;
int main() {
cin >> n;
while (n--) {
cin >> s >> p >> q;
for (i = 0; i < s.size(); i++)
if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] + 'a' - 'A';
for (i = 0; i < q.size(); i++)
if (q... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,m,A;
cin>>a>>b>>c;
m=max(a,max(b,c));
A=a+b+c-m;
cout<<A<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
int Q, A, B, C, D;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> Q;
FOR(i,1,Q) {
cin >> A >> B >> C >> D;
int K = (max(A,B)+min(A,B... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int bins(int curInd, int d, int n, int* a) {
int l = 1;
int r = n;
int x = a[curInd + 1] - 1 + d;
if (a[n] < x) return n + 1;
while (l <= r) {
int m = (l + r) / 2;
if (a[m] >= x) {
r = m - 1;
continue;
} else if (a[m] ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = N * 25;
int n, m;
long long C[M], x, y, tar[N], dep[N], in[M];
int fir[N], ne[M], to[M], cnt = 1, fa[N], fan[N];
void add(int x, int y) {
ne[++cnt] = fir[x];
fir[x] = cnt;
to[cnt] = y;
}
void link(int x, int y) {
add(x, y);
add... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll next(ll n, ll k)
{
ll num = n + n / (k - 1);
for (ll i = 1;; i++) {
if (num - (num / k) - 1 == n) {
return num;
}
num++;
}
}
int main()
{
ll N, k;
cin >> N >> k;
ll num = 0;
for (ll ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b;
long long int c, d;
long long int f = 0, g = 0;
long long int a1 = 0, a2 = 0;
long long int b1 = 0, b2 = 0;
cin >> a >> b;
c = a + b;
while (c) {
if (c % 10 != 0) f = f * 10 + c % 10;
c = c / 10;
}
while (f) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
const int N = 2005;
int n, m;
vector<vector<char>> a;
vector<vector<int>> c, u;
bool check2(int i, int j, int i1, int j2) {
if (i < 1 || j < 1 || i1 < 1 || j2 < 1) return 0;
if (i > n || j > m || i1 > n || j2 > m) re... | 5 |
#include<algorithm>
#include<cstdio>
#include<cstring>
#define M 10001
#define N 101
using namespace std;
int A[N][N],B[M],C[N][N],D[N][N],b[N],d[N],m,n;bool a[N][N],c[N];
bool dfs(int u)
{
c[u]=true;
for(int i=1;i<=n;i++)if(a[u][i]&&(!d[i]||!c[d[i]]&&dfs(d[i])))
{
b[d[i]=u]=i;
return true;
}
return false;
}
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long n, m, a[200020], dp[200020][2];
vector<pair<long long, long long> > seg[200020];
void Solve() {
cin >> n >> m;
for (long long i = 2; i <= n + 1; ++i) {
cin >> a[i];
}
sort(a + 2, a + n + 2);
a[1] = -inf;
a[n + 2] = inf;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int T = 1e5 + 5;
struct node {
int num, x;
} t;
vector<node> p[T];
bool flag[T];
int dfs(int now) {
queue<int> q;
int l = p[now].size();
for (int i = 0; i < l; i++) {
node k = p[now][i];
if (flag[k.num])
continue;
else
flag[k.num] = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 1e6 + 10;
const int INF = 0x3f3f3f3f;
int casn, n, m, k;
int st, pre[maxn], deg[maxn];
int to[maxn], nex[maxn], head[maxn], nume;
int dfn[maxn], cnt, ans1[maxn], ans2[maxn], cnt2;
void dfs(int now) {
for (int i = head[now]; i; i... | 2 |
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,string> P;
int main(){
int n;
string str;
while(1){
cin >> n;
if(n == 0) break;
map<string,int> count;
vector<P> v;
getchar();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007
lli b(lli bit){
if(bit)return -1;
else return 1;
}
signed main(){
lli n,m;
cin>>n>>m;
vector<lli> x(n),y(n),z(n);
REP(i,0,n)cin>>x[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, maxm = (1 << 17), mod = 1e9 + 7, hash = 701;
const double PI = 3.14159265359, E = 2.71828;
long long a[maxn];
pair<long long, long long> d[maxn];
int main() {
ios::sync_with_stdio(0);
long long n, sum;
cin >> n;
for (int i = 1; i <= n; i++... | 4 |
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long... | 1 |
#include <bits/stdc++.h>
using namespace std;
namespace std {
bool operator<(const complex<double> &lhs, const complex<double> &rhs) {
if (real(lhs) == real(rhs)) {
return imag(lhs) < imag(rhs);
} else {
return real(lhs) < real(rhs);
}
}
} // namespace std
ostream &operator<<(ostream &os, const complex<d... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x1, x2;
cin >> n;
long long ans[n + 1], prev = 1;
for (long long i = 2; i <= n; i++) {
cout << "? " << prev << " " << i << endl;
cin >> x1;
cout << "? " << i << " " << prev << endl;
cin >> x2;
if (x1 > x2) {
ans[... | 3 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b)... | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
int arr[3][101];
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < (int)(n); ++i) cin >> arr[0][i];
for (int i = 0; i < (int)(n); ++i) cin >> arr[1][i];
for (int i = 0; i < (int)(n); ++i) cin >> a... | 1 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,m,i,j,x,f[1010][1010];
char a[1010][1010];
int main(){
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)scanf("%s",a[i]+1);
memset(f,44,sizeof(f));
if(a[1][1]=='.')f[1][1]=0;
else f[1][1]=1;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++){
if(i<n){
x=0;
... | 0 |
#include <iostream>
using namespace std;
int main() {
int A, B, K;
cin >> A >> B >> K;
for (int i = 0; i < K; ++i) {
if (i % 2) {
A += B / 2;
B /= 2;
}
else {
B += A / 2;
A /= 2;
}
}
cout << A << " " << B;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, m;
struct node {
int x, can;
} a[N];
bool cmp(node x, node y) {
if (x.can != y.can) return x.can < y.can;
return x.x > y.x;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], f[100005][320], n, m, t, x, k;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
t = int(sqrt(double(n)));
cin >> m;
for (int i = 1; i <= t; i++) {
for (int j = n; j >= 1; j--) {
if (j + a[j] + i > n)
f[j][i] = 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <int R, int C, class T>
struct Matrix {
T m[R][C];
inline T *operator[](int r) { return m[r]; }
inline const T *operator[](int r) const { return m[r]; }
};
template <int R, int C, class T>
void print(const Matrix<R, C, T> &m) {
int w = 1;
for (int r = int... | 4 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> ints(pair<int, int> a, pair<int, int> b) {
if (a.first > b.first) swap(a, b);
if (b.first > a.second) return {1050000000, -1050000000};
int end(min(a.second, b.second));
return {b.first, end};
}
void solve() {
int n;
scanf("%d", &n);
vector<pair... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct vertex {
char type;
vector<int> in;
bool val;
bool change;
};
int n;
vector<vertex> g;
int dfs1(int v) {
switch (g[v].type) {
case 'A':
g[v].val = dfs1(g[v].in[0]) & dfs1(g[v].in[1]);
break;
case 'O':
g[v].val = dfs1(g[v].in[0]) | ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, i, ans;
cin >> a >> b;
if (a == b) {
cout << "infinity\n";
return 0;
}
a -= b;
ans = 0;
for (i = 1; i * i <= a; i++) {
if (!(a % i)) {
if (i > b) ans++;
if (i * i < a && a / i > b) ans++;
}
}
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, d, x, a[101010], b[101010], c[101010], ans, s, mp[101010], k;
vector<int> v;
long long getNextX() {
x = (x * 37 + 10007) % 1000000007;
return x;
}
void initAB() {
int i;
for (i = 0; i < n; i = i + 1) {
a[i] = i + 1;
}
for (i = 0; i < n; i = i + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ff[55], ss[55];
long double p[55];
long double dp[55][5500];
int n, r;
bool check(long double ans) {
for (int j = 0; j <= r; ++j) {
if (n == 1 and j == r) {
dp[n][r] =
p[n] * (ff[n] <= j ? (long double)ff[n] : (long double)ff[n] + ans) +
... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.