solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m;
cin >> n >> m;
vector<vector<long long> > dp(2 * m + 1, vector<long long>(n + 1, 0));
for (long long j = 1; j <= n; j++) dp[1][j] = 1;
for (long long i = 1; i <= 2 * m; i++) dp[i... | 3 |
#include <bits/stdc++.h>
const int N = 1e3 + 10;
using namespace std;
int n, a[N];
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int ans = min(a[0], a[n - 1]);
int x = 1e9;
for (int i = 1; i < n - 2; i++) x = min(x, max(a[i], a[i + 1]));
cout << min(x, ans);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 300000;
int n, m, k, nk, par[maxn], lvl[maxn];
vector<int> G[maxn];
struct Cycle {
int r, lo, hi;
Cycle(int _r, int _lo, int _hi) : r(_r), lo(_lo), hi(_hi) {}
int length() const { return lvl[lo] - lvl[hi] + 1; }
bool operator<(const Cycle& b) co... | 3 |
#include <bits/stdc++.h>
int B[2000];
using namespace std;
int main() {
int n, k, i, j, ans, pos, min;
int A[2000];
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", &A[i]);
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) {
if (A[j] - A[i] != (j - i) * k && A[i] + (j - i) * k > 0)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum[3];
for (int i = 0; i < 3; i++) sum[i] = 0;
for (int i = 0; i < n; i++) {
int a[3];
cin >> a[0] >> a[1] >> a[2];
for (int i = 0; i < 3; i++) sum[i] += a[i];
}
if (sum[0] == 0 && sum[1] == 0 && sum[2] == 0)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long n, m;
cin >> n >> m;
vector<long long> victories(n, 0);
for (long long i = 0; i < m; ++i) {
long long max_voices = -1, vinner_index = -1;
for (long long j = 0; j < n; ++j) {
long long n_voices;
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long i = 1;
for (; i < n + 1; i++) cin >> arr[i];
long long j;
for (i = 1; i < n; i++) {
for (j = 1; j <= (n - i); j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int sum = 0, prev;
while (n > 1) {
sum += n;
prev = n;
for (int i = 0; i < 16; i++) {
if (n % primes[i] == 0) {
n /= primes[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200020;
int n, a[Maxn];
long long sum[Maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 0; i < n - 1; i++) {
int cur;
for (cur = 1; cur <= i;) {
int val = i / cur;
int ncur = i / val... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v, num;
node() {}
node(int V, int Num) { v = V, num = Num; }
};
queue<int> q;
vector<node> G[200005];
vector<int> edge[200005];
int n, m, k;
int dep[200005];
bool vis[200005];
void bfs() {
q.push(1);
while (!q.empty()) {
int u = q.front();
... | 6 |
#include <stdio.h>
typedef long long ll;
int main(void) {
ll i, j, now = 0, a, n;
scanf("%lld", &n);
for(i = 0; i < n; ++i) {
scanf("%lld", &a);
if(a == now + 1) now++;
}
printf("%lld", now ? n - now : -1);
return 0;
} | 0 |
#include<queue>
#include<string>
#include<cstdio>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
for(int n,m;scanf("%d%d",&n,&m),n;){
vector<int> G[15];
rep(i,m){
int u,v; scanf("%d%d",&u,&v); u--; v--;
G[u].push_back(v);
G[v].push_back(u);
}
int S_ini... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long num[300005];
long long tmp[300005];
struct node {
int id;
int a, b;
long long ans;
node() { ans = 0; }
} p[300005];
vector<node> v[300005];
int main() {
int n;
scanf("%d", &n);
int i, j;
for (i = 1; i <= n; i++) {
scanf("%d", &num[i]);
}
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int ct = 0;
cin >> s;
int sz = s.size();
for (int i = 0; i < sz; i++) {
if (s[i] == 'Q') {
for (int j = i + 1; j < sz; j++) {
if (s[j] == 'A') {
for (int k = j + 1; k < sz; k++) {
if (s[k] == 'Q') ct++... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
double a, b, c, C;
double S,L,h;
cin>>a>>b>>C;
h = b*sin(C/180*M_PI);
S = a * h / 2;
c = sqrt((pow(a,2)+pow(b,2) - 2 * a * b * cos(C/180*M_PI)));
L = a+b+c;
printf("%10lf\n", S);
printf("%10lf\n", L);
printf("%10lf\n", h);
} | 0 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX_N = 300010;
int p[MAX_N];
vector <int> g[MAX_N];
vector <int> new_g[MAX_N];
int pairs[MAX_N];
int used[MAX_N];
vector <int> sets[MAX_N];
vector <int> order;
void dfs(int v, bool &foundCycle) {
used[v] = 1;
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m;
int t[maxn], c[maxn];
int vis[maxn];
bool check(int x) {
memset(vis, false, sizeof vis);
int sum = 0;
int cnt = 0;
for (int i = x; i >= 1; --i) {
if (t[i] != 0 && !vis[t[i]]) {
vis[t[i]] = true;
sum += c[t[i]];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool vis[10000001];
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return ((a * b) / gcd(a, b)); }
int main() {
int n;
scanf("%d", &n);
int sum = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int b[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
sum -= b[i];
}
if (sum < 0)
cout << "No";
else
cout << "Yes";
}
| 1 |
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
//const double EPS = 1e-9;
int n,t;
long double dp[2001][2001];
string str;
void solve(){
fill(dp[0],dp[2001],0.0);
dp[0][0] = 1.0;
for(int i=0;i<t;i++){
for(int j=0;j<n;j++){
//if(dp[i][j] < EPS) contin... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k;
long double t, s = 0, v = 0, ss, vv, EPS = 1E-10, x, a, b, c;
cin >> n >> t;
vector<long double> aa(n), tt(n);
vector<pair<long double, long double>> pp;
for (i = 0; i < n; i++) cin >> aa[... | 5 |
#include<iostream>
#include<iomanip>
using namespace std;
int main() {
double a;
double answer;
while (cin >> a) {
answer = a;
for (int i = 2; i < 11; ++i) {
answer+=(i % 2 ? a /= 3.0 : a *= 2.0);
}
cout <<setprecision(10)<< answer<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
vector<int> g[N], h[N];
int mark[N][2];
char ans[N];
void dfs(int v) {
mark[v][0] = 1;
for (int u : g[v]) {
if (!mark[u][0])
dfs(u);
else if (mark[u][0] == 1) {
cout << -1;
exit(0);
}
}
mark[v][0] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a[1001];
double F[1001][1001], ans;
void Mix(double &a, double &b) { a = b = (a + b) / 2; }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
F[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 123123;
string a[N], b[N];
int p[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
for (int i = 0; i < n; i++) cin >> p[i];
for (int i = 0; i < n; i++) p[i]--;
st... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r;
int a[31];
int b[31];
int main() {
cin >> n >> m >> r;
int mina = 0x7fffffff;
int maxb = -0x7fffffff;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
mina = min(mina, a[i]);
}
for (int i = 1; i <= m; ++i) {
cin >> b[i];
maxb = max(maxb, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using LD = long double;
struct d {
LL a, b;
};
d devices[100005];
LL n, p;
bool f(LD med) {
LD check = 0;
for (int i = 0; i < n; i++) {
check += max((long double)0.0, med * devices[i].a - devices[i].b) / med;
}
return check <= p;
}
int ma... | 1 |
#include <bits/stdc++.h>
using namespace std;
char c[200001];
int a[200001];
void query() {
long long n, m;
cin >> n;
for (int i = 1; i < n; ++i) {
cin >> c[i];
}
int cur, i = 1;
cur = n;
while (i < n)
if (c[i] == '<') {
int l = i, r = i;
while (c[r] == '<' && r < n) ++r, --cur;
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
vector<long long> tree, mxi, tag, a;
int T;
void push(int i, int l, int r) {
if (tag[i]) {
tree[i] += tag[i];
if (l != r) {
tag[((i << 1) + 1)] += tag[i];
tag[((i << 1) + 2)] += tag[i];
}
tag[i] = 0;
}
}
void pull(i... | 6 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2010;
const ll inf=1e18;
int n,sz[N];char s[N];ll ds[N],dz[N],sn[N];
vector<int>g[N];
void dfs(int u,int fa){
sz[u]=s[u]-'0';
ll sum=ds[u]=sn[u]=0,mx=0;
for(int v : g[u]){
if(v==fa)continue;
dfs(v,u);
ds[u]+=ds[v]+sz[v];sz[u]+=sz[v... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, cnt, ans;
int Q[200010], s1[200010], s2[200010], a[200010], pre[200010], nxt[200010];
char s[2][200010];
bool vis[200010];
int main() {
int lst, x, y, tp1, tp2;
scanf("%d%d", &n, &m);
scanf("%s", s[0] + 1);
scanf("%s", s[1] + 1);
for (int i = 1; i <= n; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long seg[4 * N], a[N];
void build(int p, int s, int e) {
if (s == e) {
seg[p] = a[s];
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 400;
long long dp[N][N];
long long did_dp[N][N];
vector<pair<long long, long long> > a;
long long n;
vector<long long> events;
const long long INF = 1e18;
void mmin(long long &a, long long b) { a = min(a, b); }
void mmax(long long &a, long long b) { a = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[55][55];
while (cin >> n) {
int maxn = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (a[i][j] > maxn) {
maxn = a[i][j];
}
}
}
if (maxn == 1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, m, d;
cin >> n >> k >> m >> d;
long long ans = 0;
for (int i = 1; i <= d; i++) {
long long t = n / ((i - 1) * k + 1);
if (t < 1) break;
long long x = min(t, m);
ans = max(x * i, ans);
}
cout << ans << endl;
return 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long pow_mod(long long a, long long b) {
long long ans = 1;
a %= mod;
while (b) {
if (b & 1) ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
int judge(char s) {
if (s == 'A')
return 0;
else if... | 3 |
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloa... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9, oo = 1e9;
bool a[105][105];
void solve() {
int k, n = 3;
cin >> k;
while (n * (n - 1) * (n - 2) < k * 6) n++;
if (n * (n - 1) * (n - 2) != 6 * k) n--;
for (int i = 0; i < n; i++) {
a[i][i] = 0;
for (int j = i + 1; j < n; j++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;++i)
#define per(i,a,b) for(int i=(a),i##end=(b);i>=i##end;--i)
//mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template<typename T>void chkmax(T&x,T y){if(x<y)x=y;}
template<typename T>v... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000005;
char s[MAX];
int z[MAX];
void zfun(int n) {
int l = 0, r = 0;
for (int i = 1; i < n; ++i) {
if (i <= r) z[i] = min(z[i - l], r - i + 1);
while (i + z[i] < n && s[i + z[i]] == s[z[i]]) z[i]++;
if (i + z[i] - 1 > r) l = i, r = i + z[i]... | 2 |
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
typedef long long ll;
using namespace std;
#define all(x) x.begin(), x.end()
const ll INF = 1e9;
ll n;
ll xs, ys, xf, yf;
ll x[5000], y[5000], r[5000];
double d[1111][1111];
double dist(int i, int j)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const long long INF = 1000000000 + 9;
const long double EPS = 1e-9;
const long double PI = acos(-1);
char s1[MAXN], s2[MAXN];
int k4, k7, len;
void Input() {
ifstream in("INPUT.TXT");
cin >> s1;
cin >> s2;
in.close();
}
void Solution() ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e2 + 10;
int a[N], cont[N];
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cont[a[i]]++;
}
int ans = 0;
bool ok1 = true, ok2 = true;
f... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N;
cin>>N;
int a=(N%10);
if(a==2 || a==4||a==5||a==7||a==9) {cout<<"hon";}
else if(a==3) {cout<<"bon";}
else {cout<<"pon";}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = s * 10 + ch - '0';
ch = getchar();
}
return s * w;
}
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dp[100000][16][12];
inline bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int m;
int mod = 1000000007;
int dp_func(int pos, int mask, int koyta) {
if (check(mask, m)) mask = mask ^ (1 << m);
if (koyta == 0) return 1;
if (pos == -1) {
if (k... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int l[MAXN], a[MAXN], r[MAXN], n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
l[1] = 1;
for (int i = 2; i <= n; i++) l[i] = min(l[i - 1] + 1, a[i]);
r[n] = 1;
for (int i = n - 1; i >= 1; i--) r[i] = m... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MAXN = 100005;
int n, m, arr[MAXN];
int main() {
cin >> n >> m;
long long tot = 0;
for (int x = 1; x <= n; x++) {
cin >> arr[x];
tot = tot + arr[x];
}
sort(arr + 1, arr + n + 1);
long long nyak = arr[n];
long lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, r, k;
long long calc(long long row, long long col) {
long long x = min(col, m - r + 1LL) - max(1LL, col - r + 1LL) + 1LL;
long long y = min(row, n - r + 1LL) - max(1LL, row - r + 1LL) + 1LL;
return x * y;
}
int main() {
scanf("%lld%lld%lld%lld", &n, ... | 4 |
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
ll max(ll a,ll b) {return a<b?b:a;}
ll cmp(const ll &x,const ll &y) {return x>y;}
ll a[4][110];
int main()
{
int n;
ll W,w1,w,x,ans=0;
scanf("%d%lld",&n,&W);
scanf("%lld%lld",&w1,&x);
a[0][1]=x;a[0][0]=1;
for(int i=1;i<n;i++)
{
sca... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 260005, MAX_W = 500;
struct GRIPPER {
int m, p, r;
long long d;
} grip[MAX_N];
int x, y, n, X, Y, top;
int p[MAX_N], r[MAX_N];
int L[1000], R[1000];
long long D[1000];
bool vis[MAX_N];
bool cmp_d(GRIPPER a, GRIPPER b) { return a.d < b.d; }
bool cmp_m(G... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1 << 20, INF = 2e9;
int dp[M], n, m, cost[25][25];
char s[25][25];
void Min(int &a, int b) {
if (a > b) a = b;
}
void rd(int &res) {
char c;
res = 0;
while (c = getchar(), !isdigit(c))
;
do res = (res << 3) + (res << 1) + (c ^ 48);
while (c = g... | 5 |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
usi... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int K = 10;
const int N = 500500;
int n;
int a[N];
char b[N];
bool Res[K][2];
int f(int i, int x, int bit) {
if (i == n) return x;
bool cur = (a[i] & (1 << bit));
if (b[i] == '&') return f(i + 1, x & cur, bit);
if (b[i] == '|') return f(i + 1, x | cur, bit);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
const int smax = 1e3;
long long int ans, n, m, x, y, k;
long long int a[maxn + 10];
long long int b[maxn + 10];
vector<int> g[maxn + 10];
set<int> se[maxn + 10];
string s;
long int mat[smax + 10][smax + 10];
int main() {
cin >> n >> m;
memset(a, 0,... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n,l;
char s[5010];
long long dp[5010][5010];
const long long mod=1e9+7;
inline long long ksm(long long x,long long y,long long mod)
{
long long res=1;
while(y)
{
if(y&1)
res=res*x%mod;
x=x*x%mod;
y>>=1;
}
return res;
}
int main()
{
scanf("%d",&n);
scanf(... | 0 |
#include <bits/stdc++.h>
using namespace std;
void maxify(long long &a, long long b) { b > a && (a = b); }
void minify(long long &a, long long b) { b < a && (a = b); }
struct IOManager {
template <typename T>
inline bool read(T &x) {
char c;
bool flag = false;
x = 0;
while (~c && !isdigit(c = getcha... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &first, T2 second) {
if (first > second) first = second;
}
template <typename T1, typename T2>
inline void chkmax(T1 &first, T2 second) {
if (first < second) first = second;
}
const string FileName = "input";
con... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
class dsu {
public:
vector<int> p;
int n;
dsu(int _n) : n(_n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
}
inline int get(int x) { return (x == p[x] ? x : (p[x] = get(p[x]))); }
inline bool unite(int x, int y) {
x = get(x);... | 4 |
#include<cstdio>
int main(){
int n,h,w;
scanf("%d%d%d",&n,&h,&w);
printf("%d",(n-h+1)*(n-w+1));
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, mis = 0, chs = 0, m, c;
cin >> n;
while (n--) {
cin >> m >> c;
if (m > c) {
mis++;
} else if (m < c) {
chs++;
}
}
if (mis > chs) {
cout << "Mishka" << endl;
} else if (chs > mis) {
cout << "Chris" << end... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x7fffffff;
int n, k;
int head[maxn], e;
int d[maxn][3], pos[maxn][2], dist, core;
bool vis[maxn];
struct Edge {
int u, v;
int next, len;
} edge[maxn * 2];
void addedge(int u, int v, int l) {
edge[e].u = u;
edge[e].v = v;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool visited[50];
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
long long n, u, v;
vector<long long> adj[50];
vector<pair<long long, long long> > vec(50);
set<pair<long long, long long> > points;
void dfs(long long u, long long dir, long long pow) {
long... | 5 |
#include <bits/stdc++.h>
using namespace std;
int dp[26][26];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string name;
cin >> name;
int f = name[0] - 'a';
int l = name[name.size() - 1] - 'a';
for (int i = 0; i < 26; i++)
if (dp[i][f]) {
dp[i][l] = max(dp[i][l], dp... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int x[N];
long long powmod(long long b, long long p) {
long long r = 1;
for (; p; p >>= 1, b = b * b % mod)
if (p & 1)
r = r * b % mod;
return r;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, a, b, ans, k;
cin >> t;
for (int i = 0; i < t; ++i) {
cin >> a >> b;
ans = abs(a - b) / 10;
if (a <= b) {
a += ans * 10;
} else {
b += ans * 10;
}
if (a != b) {
ans++;
}
cout << ans;
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const size_t DEEP = 40;
int main() {
int q;
scanf("%d", &q);
vector<int> pr(2);
vector<vector<double>> f(2);
f[1] = vector<double>(DEEP, 1.0);
while (q--) {
int type, v;
scanf("%d%d", &type, &v);
if (type == 1) {
pr.push_back(v);
f.push_b... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, inf = 1e9;
int n, kk, s, x, k[N][2];
char ch[N];
int fa[N << 1], val[N << 1];
int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); }
void uni(int a, int b) {
if (find(a) == find(b)) return;
val[find(b)] += val[find(a)];
fa[find(a)]... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=300005,p=1000000007;
int read(){
int f=1,g=0;
char ch=getchar();
for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
return f*g;
}
int n,a[N],h[N];
bool check(int l,int r){
int x=0,y=0;
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int m;
int n;
int w[1000];
int mod = 1000000000 + 7;
long long st2[1500];
long long fact[1500];
long long step(long long x, long long p) {
long long ans = 1;
while (p) {
if (p & 1) ans = ans * x % mod;
x... | 3 |
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double>... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const long long int INFLL = 1000000000000000001;
const long double EPS = 1e-6;
const int MAXN = 500005;
bool visited[MAXN];
int n, k;
long long int DP[MAXN][2];
vector<pair<int, long long int>> adj[MAXN];
void Dfs(int u) {
visited[u] = true;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct sort_pred {
bool operator()(const pair<int, int> &left, const pair<int, int> &right) {
return left.second < right.second;
}
};
pair<int, int> tacka[222222];
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long long x, y;
Point(long long x = 0, long long y = 0) : x(x), y(y) {}
};
bool operator==(const Point &a, const Point &b) {
return a.x == b.x && a.y == b.y;
}
bool operator!=(const Point &a, const Point &b) { return !(a == b); }
Point operator-(const P... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long vy[4] = {-1, 0, 1, 0}, vx[4] = {0, 1, 0, -1}, inf = 1e18;
const string ky = "URDL";
long long n, m, nn, yk[26], a[2069][2069], dp[2069][2069];
bitset<2069> vtd[2069], vtd2[2069];
pair<long long, long long> ca[4000069];
int main() {
long long t, rr, i, j, r... | 6 |
#include<iostream>
#include<string>
int main(void){
std::string s;
int m,h;
while(std::cin>>s){
if(s=="-")break;
std::cin>>m;
while(m-->0){
std::cin>>h;
s=s.substr(h)+s.substr(0,h);
}
std::cout<<s<<std::endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t-- > 0) {
int a, b, c, r;
cin >> a >> b >> c >> r;
if (a > b) swap(a, b);
cout << b - a - max(0, (min(b, c + r) - max(a, c - r))) << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int mat[505][505];
int pre[505][505];
int dp[505][505];
int tot[505];
vector<pair<int, int> > comp[505];
int n, m, K;
int maxi = 1e9;
int doit(int pos, int left) {
if (left < 0) return 1e9;
if (pos == n + 1) return 0;
if (dp[pos][left] != -1) return dp[pos][left];
i... | 4 |
#include <bits/stdc++.h>
int main() {
puts("2");
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, k, t, ans;
vector<long long> f;
int main() {
ios_base::sync_with_stdio(0);
static const size_t npos = -1;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> j;
f.push_back(j);
}
sort(f.rbegin(), f.rend());
for (i = 0; i < n; i += k)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 25;
int a[MaxN], sum[1 << 15];
int dp[MaxN][MaxN][1 << 15];
int n, leaf, x;
bool f(int u, int leaf, int mask) {
if (leaf < 0) return false;
if (u == 0 && !leaf) return true;
if (u == 0) return false;
int &r = dp[u][leaf][mask];
if (r != -1) return... | 5 |
#include <bits/stdc++.h>
using namespace std;
int filter[3000000];
int prime[3000000];
vector<int> factors[2000010];
int n, m;
vector<int> edgev[100010];
int value[100010];
int ans[100010];
int depth[100010];
vector<int> calfactor(int num) {
vector<int> resu;
while (filter[num]) {
resu.push_back(filter[num]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long power(long long x, long long y, long long m) {
if (y == 1)
return x % m;
else if (y % 2)
return (x * power(x, y - 1, m)) % m;
long long val = power(x, y / 2, m) % m;
return val * val;
}
int main() {
cin >> n >> m;
cout << (power... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, fa[maxn + 2], cont[maxn + 2];
int mx1[maxn + 2], mx2[maxn + 2], diameter[maxn + 2];
bool vist[maxn + 2];
vector<int> G[maxn + 2];
vector<long long> dist[maxn + 2];
map<pair<int, int>, double> Map;
void dfs1(int x, int pre, int col) {
vist[x] =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int BASE = 100002;
int N, M, K;
set<pair<int, int> > S1[300002], S2[300002];
set<pair<int, int> > S;
void add(int x, int y) {
S.insert(make_pair(x, y));
S1[BASE + x - y].insert(make_pair(x, y));
S2[x + y].insert(make_pair(x, y));
}
int block(int x, int y) { retu... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
char pc, c, x;
int main(int argc, const char* argv[]) {
cin >> N >> M;
pc = '.';
for (int n = 0; n < N; n++) {
cin >> c;
if (c == pc) {
cout << "NO" << endl;
return 0;
}
for (int m = 1; m < M; m++) {
cin >> x;
if (x !=... | 1 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, n, m, s, t, tot, id, J, S;
long long ans, tmp, all;
int fa[200005][25];
int rmax[200005][25];
int head[200005];
int dep[200005];
int f[200005];
int flag[200005];
struct edge {
int vet, next, len, id;
} E[400005];
int a[200005];
int b[200005];
struct data {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, t, k;
int cost[22][22];
bool used[22];
int numFind;
int anss[200005];
priority_queue<int> pq;
void back(int num, int get) {
if (num == n) {
if (numFind >= t) {
if (!pq.empty() && get < pq.top()) {
pq.pop();
pq.push(get);
}
} else... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long binPow(long long a, long long b) {
long long res = 1;
while (b) {
if (b % 2) res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long l... | 2 |
#include <bits/stdc++.h>
using namespace std;
void print(priority_queue<int, vector<int>, less<int> > pq, int res) {
int cnt = 0;
while (pq.size() && res > 0) {
int u = pq.top();
res -= u;
pq.pop();
++cnt;
}
cout << cnt << " ";
return;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_wi... | 3 |
#include <bits/stdc++.h>
long long phi(long long a) {
long long ans;
ans = a;
for (long long i = 2; i * i <= a; i++) {
bool f(0);
while (!(a % i) && a != 1) f = 1, a /= i;
if (f) ans -= ans / i;
}
if (a != 1) ans -= ans / a;
return ans;
}
bool pd;
long long pow(long long a, long long b, long lon... | 4 |
#include <bits/stdc++.h>
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;
int vis[1001][1001];
char str[101];
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int main() {
int len, x = 500, y = 500, flag = 0;
scanf("%s", str);
len = strlen(str);
vis[x][y] = 1;
for (int i = 0; i < len; i++) {
if (str[i] == 'L') {
x--;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int n;
int ans;
int tr[N];
int lowbit(int x) { return x & -x; }
int sum(int x) {
int res = 0;
for (int i = x; i; i -= lowbit(i)) res += tr[i];
return res;
}
void init() {
for (int i = 0; i <= n; i++) tr[i] = 0;
}
void add(int x, int c) {
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1>
void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) {
cout << "{";
if (start < 0) start = 0;
if (end < 0) end = V.size() - 1;
for (int i = start; i <= end; i++) {
cout << V[i] + add << ((i == end) ? "}" : " ");
}
}
void ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int A[100010];
struct query {
int t, x, c;
int get_index(int i) {
assert(1 <= i && i <= length());
if (t == 1) {
return x;
} else {
i = (i - 1) % x + 1;
return A[i];
}
}
int length() { return ((t == 1) ? 1 : (1 * x * c)); }
};
query... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, w = 0;
char ch = getchar();
while (!isdigit(ch)) w |= ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
return w ? -x : x;
}
inline long long ksm(long long x, long long y) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-12;
const int mod = 1e9 + 7;
const int maxn = 300005;
using namespace std;
int c[401];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> c[i];
int ans = -1;
for (int i = 1; i < n; i++) {
for (int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
bool ava[200005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
ava[a[i]] = true;
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
bool strt = true;
int ind = -1;
for (int i = n - 1; i >= 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v(2);
int main() {
::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
int a, b;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
if (a > 0)
v[0]++;
else
v[1]++;
}
if (v[0] == 0 || v[0] == 1 |... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.