solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, c[200005], p[200005], q[200005], cnt[200005], ans[200005];
void add(int i, int x) {
for (; i <= n + 1; i += i & -i) c[i] += x;
}
int sum(int i) {
int s = 0;
for (; i > 0; i -= i & -i) s += c[i];
return s;
}
int main() {
scanf("%d", &n);
for (int i = 0; i ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e9 + 7;
vector<int> v[500005];
int vis[500005];
vector<int> c;
void dfs(int x) {
vis[x] = 1;
c.push_back(x);
for (auto it : v[x]) {
if (vis[it] == 0) dfs(it);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
long long x = s[i] - '0';
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, x;
cin >> n >> x;
vector<long long> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<vector<long long> > dp(n + 1, vector<long long>(5, -1e9));
for (int i = 0; i < 5; ++i) dp[0][i] = 0;
for (int i = 1; i <= n; ++i) {
dp[i][1] = a... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T alex(T x) {
return (x > 0) ? x : -x;
}
template <class T>
void read(T& x) {
x = 0;
T f = 1;
char ch = getchar();
while ((ch < 48 || ch > 57) && ch != 45) ch = getcha... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, a[N], qL[N], qR[N], bit[N], ans[N];
vector<int> vec[N];
int lowbit(int x) { return x & (-x); }
void insert(int k, int x) {
for (; k <= n; k += lowbit(k)) bit[k] += x;
return;
}
int query(int k) {
int res = 0;
for (; k > 0; k -= lowbi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
int MAXN;
vector<long long> S, D;
vector<pair<long long, pair<long long, long long> > > C[2];
void input();
void solve();
long long dist(long long, long long, int);
pair<long long, long long> toFL(long long, int);
int main() {
input();
solve();
return 0;
}
v... | 5 |
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> c;
int p[100010];
set<int> pr;
int t[100010];
void solve() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
p[i] = a;
if (pr.empty()) {
pr.insert(a);
continue;
}
auto up = pr.upper_bound(a), it = pr.en... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<string> getRoot(int a3, int a4, int a1, int a2) {
vector<string> ret;
string s = "";
int x = 0, y = 0;
int c1 = a1, c2 = a2;
bool flag = true;
for (int i = 0; i < 2; i++) {
while (true) {
if (flag) {
if (s.size() > 0 && s[s.size() - 1] =... | 2 |
#include <bits/stdc++.h>
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 4000000;
using namespace std;
struct {
long long ans, open, close;
} t[MAXN], res;
long long l, r;
void modify(long long v, long long tl, long long tr, long long pos,
long long v1,... | 5 |
#include<iostream>
#include<vector>
#define MAX 10000000
using namespace std;
int main(){
int n;
vector<char> a;
vector<int> box;
for(int i=0;i<=MAX;i++)
a.push_back('1');
a[0]='0';
a[1]='0';
for(int i=2;i<=MAX;i++)
if(a[i]=='1'){
if(i>=13&&(a[i]=='1'&&a[i-2]=='1'&&a[i-6]=='1'&&a[i-8]=='1')){
box.push_bac... | 0 |
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
#define int long long int
void fun()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) {
if(a == 0) return b;
return gcd(b % a, a);
}
const... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> ms(10, -1e18);
ms[0] = 0;
for (int k, i = 0; i < n; i++) {
vector<long long> nms(10, -1e18);
cin >> k;
multiset<int> d1;
int d2 = 0, d3 = 0;
int c, d;
for (int j = 0; j < k; j++) {
cin >... | 6 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;
int main(){
string n;
cin>>n;
int sz=n.size();
int dp[sz+1][2];
dp[0][0]=0;
dp[0][1]=1;
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200001];
bool vis[200001];
int c = 0;
int ms = 0, l, sz = 0, nd;
bool flag = true;
void check(int s) {
vis[s] = true;
if (adj[s].size() == 2) {
for (auto it : adj[s]) {
if (!vis[it]) {
sz += adj[it].size() - 1;
nd++;
l =... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const ll inf=1000000000000;
#define rep(i,m,n) for(ll i=m;i<n;i++)
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll n;
cin >>... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
long long x, y;
long long pos;
Node(long long x = 0, long long y = 0, long long pos = 0)
: x(x), y(y), pos(pos){};
};
Node a[100005], b[100005];
bool vis[100005];
long long n, ans, k;
bool compare1(Node a, Node b) { return a.x < b.x; }
void dfs(int... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vpi = vector<pair<int, int>>;
using vvi = vector<vi>;
int Bit(int mask, int b) { return (mask >> b) & 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
int X[100005], Y[100005], W[100005];
pair<int, int> R[100005];
set<pair<int, int> > S[100000 + 100005], s;
bool is_pleasing(int idx) {
if (!R[idx].first && !R[idx].second) {
s.insert(R[idx]);
return true;
}
if (!R[idx].first) {
if (s.find(pair<int, int>(0,... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << "0 0 " << n;
return 0;
}
| 1 |
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 50 + 2;
const int MOD = 1000000007;
inline int inc(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); }
inline int dec(int a, int b) { return (a >= b) ? (a - b) : (a + MOD - b); }
inline int mu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
vector<int> pos(26, -1);
int a, b, c;
for (int i = 0; i < s.size(); i++) {
int x = s[i] - 'A';
if (pos[x] != -1) {
a = pos[x];
c = i - pos[x] - 1;
b = i;
break;
}
pos[x] = i;
}
if (c == 0... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+7;
typedef long long LL;
int n,sum;
string s;
int quick(int a,int b,int mod){
LL ans=1;
while(b){
if(b&1) ans = ans*a%mod;
a = (LL)a*a%mod;
b>>=1;
}
return ans;
}
int fun(int n){
int ans=0;
while(n){
ans++;
n =n &(n-1);
}
return ans;
}
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
bool used[2010], freed[2010];
long long f[2010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int a;
scanf("%d ", &a);
if (!~a) continue;
used[a] = freed[i] = true;
}
for (int i = 1; i <= n; ++i)
if (!used[i])
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double l, p, q;
cin >> l >> p >> q;
double ans = (p * l) / (p + q);
std::cout << std::setprecision(5) << ans << '\n';
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> memo(1001, vector<long long>(1001, -1));
long long cnk(long long n, long long k) {
if (memo[n][k] == -1) {
if (n < k)
memo[n][k] = 0;
else if (n == k)
memo[n][k] = 1;
else if (k == 0)
memo[n][k] = 1;
else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> arr(n, 0);
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
map<long long int, vector<long long int>> ans;
for (long long int i = 0; i < n; i++) {
long long int x = arr[i], c = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int d[200000], n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= 1e5; i++) d[i] = -1;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
int ans = 0;
for (int j = 1; j * j <= x; j++)
if (x % j... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long N, E, V;
long long e, ans;
long long son[310];
long long A[310], B[310];
long long f[310];
long long ed[610], nxt[610];
long long second[200010], T[200010], W[200010];
long long p[310], C[310];
void adde(long long i, long long j) {
e++;
ed[e] = j;
nxt[e] = s... | 3 |
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e;
int main(){
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
printf("%d\n",max((c-a)*60+d-b-e,0));
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
long long n, k;
char s1[N], s2[N];
signed main() {
cin >> n >> k;
cin >> s1 + 1;
cin >> s2 + 1;
long long tmp = 1, ans = 0;
for (int i = 1; i <= n; i++) {
tmp *= 2;
if (s1[i] == 'b') tmp--;
if (s2[i] == 'a') tmp--;
if (tmp ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e+5 + 10;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
int64_t cur = 0;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
if (i & 1) a *= -1;
cur += a;
}
vector<int> b(m);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100000 + 5], b[100000 + 5];
int n, s, t;
int main() {
cin >> n >> s >> t;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int cnt = 0;
while (s != t && !b[s]) {
cnt++;
b[s] = 1;
s = a[s];
}
if (s != t) {
cout << -1 << endl;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
pair<long long, long long> p[n];
for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
long long left = p[0].first;
vector<pair<long long, long long> > vec;
multiset<long long> s;
for (int i = 1; i < n; i++) {
if (p[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6e5 + 100, MOD = 1000 * 1000 * 1000 + 7;
int sum(int a, int b) {
a += b;
if (a < 0)
a += MOD;
else if (a >= MOD)
a -= MOD;
return a;
}
void _sum(int &a, int b) { a = sum(a, b); }
int mul(int a, int b) { return 1LL * a * b % MOD; }
void _mul(int... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
int n, a[MAXN];
long long dp1[MAXN][2], dp2[MAXN][2];
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
}
void solve() {
dp1[0][0] = dp1[0][1] = 0;
for (int i = 1; i <= n; ++i) {
bool isOdd = a[i] % 2;
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int inf = 1000000000;
bool vis[200001];
vector<int> v;
long long n, m, k;
string x, y;
int dfs(int ind) {
if (vis[ind]) return 1;
vis[ind] = 1;
return dfs(v[ind]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 500010;
const int INF = 2147483640;
const double eps = 1e-8;
inline void RD(int &x) {
x = 0;
char c;
c = getchar();
bool flag = 0;
if (c == '-') flag = 1;
while (c < '0' || c > '9') {
if (c == '-') {
flag = 1;
}
c = getchar();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Friend {
int c, k, s;
} F[105];
const long long inf = 0x7fffffffffffffff;
long long a[2][1 << 20];
int cmp(Friend a, Friend b) { return a.k < b.k; }
int main() {
int n, m, k, i, j;
while (scanf("%d%d%d", &n, &m, &k) != EOF) {
for (i = 0; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c = getchar();
bool w = false;
while (c != EOF && c != '\n') {
if (c == ' ') w = true;
if (c == '.' || c == ',' || c == '!' || c == '?') {
putchar(c);
w = true;
}
if ((c != ' ' && c != '.' && c != ',' && c != '!' && c != '... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
long long ans = -1e15;
int idx;
long long sqr(long long x) { return x * x; }
long long solve(int i) {
long long res = 1LL * i * i + (a - i);
long long cnt1 = a - i + 2;
long long cnt = b % cnt1;
long long tmp = cnt * sqr((b / cnt1) + 1);
tmp += (cnt1 - c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1e9 + 7;
int n, m, k;
int a[15][15];
int f[15][15];
int Log2[1 << 12];
int use[15];
int lowbit(int x) { return x & -x; }
int dfs(int x, int y) {
if (y > m) ++x, y = 1;
if (x > n) return 1;
int res = 0, first = -1;
int bit = f[x - 1][y] | f[x][y - 1];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 200005;
struct SuffixArray {
string a;
int N, m;
vector<int> SA, LCP, x, y, w, c;
SuffixArray(string _a, int m = 256)
: a(" " + _a),
N(a.size()),
m(m),
SA(N),
LCP(N),
x(N),
y(N),
w(max(m, N)... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> tmp, v;
vector<int> dis;
int n, m;
bool hlp(int i, int j) {
if (i > n || j > m || !v[i][j]) return 0;
if (i == n && j == m) return 1;
if (tmp[i][j] != -1) return tmp[i][j];
return tmp[i][j] = hlp(i + 1, j) + hlp(i, j + 1);
}
int main() {
ios_ba... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dy[] = {1, 1, 1, 0, 0, 0, -1, -1, -1};
vector<vector<string> > a(10, vector<string>(8, string(8, '.')));
int dp[10][10][10];
int go(int n, int x, int y) {
int& res = dp[n][x][y];
if (res != -1) return res;
if (n == 8) ret... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n = 0, x[1010], y[1010], f[1010], m, d[1010][1010], c[1010][1010];
long long bin(long long x, long long a) {
long long y = 1;
while (a) {
if (a & 1) y *= x, y %= 1000000007ll;
x *= x, x %= 1000000007ll;
a >>= 1;
}
return y;
}
void pre(void) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 5;
int a[maxn];
int bo[maxn];
int fin[105];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
bo[a[i]]++;
}
sort(a + 1, a + n + 1);
int maxx = 1;
int i = 0;
while (n) {
int k = 1;
while (bo[a[i]]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long ml = 5e3 + 101;
const long long mo = 998244353;
long long n, m, k, ans, inv, mul;
long long dp[ml][ml];
inline long long read() {
long long r = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int q;
cin >> q;
int n, k, d;
unordered_map<int, int> used;
int k1 = 1, a[200001];
for (int p = 0; p < q; p++) {
k1 = 1;
cin >> n >> k >> d;
cin >> a[0];
used[a[0]] = 1;
int mn = 1;
for (int i = 1; i < n; i++) {
cin >... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000, MAXM = 30000, oo = 2000000009;
int n, m, s, t, a[MAXM * 2 + 9], b[MAXM * 2 + 9], c[MAXM * 2 + 9],
del[MAXM * 2 + 9], par[MAXN + 9], ans;
int cntNum, num[MAXN + 9], low[MAXN + 9], bridge[MAXM * 2 + 9];
vector<int> adj[MAXN + 9], vAns;
int Rev(int x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N;
string A, B;
vector<int> freqA[30];
vector<int> freqB[30];
double ans;
void solve(vector<int> a, vector<int> b) {
int j = -1;
long long int sum = 0;
for (auto i : a) {
while (j + 1 < b.size() && b[j + 1] <= i) {
++j;
sum += b[j];
}
ans +... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 5 |
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main(){
while(1){
int w, q;
int a[101];
scanf(" %d %d", &w, &q);
if(w==0) break;
memset(a, -1, sizeof(a));
for(int i=0; i<q; ++i){
char order;
scanf(" %c", &order);
if(order=='s'){
int x, y;
scanf(... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const int dy[] = {1, 0, -1, 0, -1, 1, 1, -1, 0};
template <typename X>
inline X square(const X& a) {
return a * a;
}
int scan_d() {
bool minus = false;
int result = 0;
char ch;
ch = getchar();
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int p[100002];
int main() {
int n, s, t;
scanf("%d%d%d", &n, &s, &t);
p[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
}
vector<bool> used(100002, 0);
int cnt = 0;
bool found = (s == t);
int news = s;
while (news != t && !found) {
cnt... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector <int> ans;
int v[101];
void solve ()
{
int n;
cin >> n;
for (int i = 1;i<=n;++i)
cin >> v[i];
ans.push_back(v[1]);
for (int i = 2;i<=n;++i)
{
int place = -1;
for (int j = 0;j<ans.size();++j)
if (ans[j] < v[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long inline mo(long long a) { return a % (long long)(1e9 + 7); }
long long po(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y >>= 1;
x = (x * x) % p;
}
return res % p;
}
temp... | 4 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 200000 + 2;
constexpr int maxm = 300000 + 2;
constexpr int maxq = 500000 + 2;
int a[maxm], b[maxm], d[maxm];
int type[maxq], id[maxq];
int pi[maxn], p[maxn];
vector<int> add[maxq];
pair<int*, int> cp[maxq][2];
pair<int, int> spp[ma... | 4 |
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#include <queue>
using namespace std;
double s;
int n,m,set[11000];
struct point
{
double x,y;
}p[11000];
struct edge
{
int x,y;
double w;
}e[510000];
bool cmp(const struct edge &a,const struct edge &b){return b.w<a... | 0 |
#include <iostream>
#include <vector>
int main(){
int n;
std::cin >> n;
std::vector<int> co(200000,0),dp(n,0),da(n);
int c;
std::cin >> c;
da[0]=c;
dp[0]=1;
co[c-1]=1;
for(int i=1;i<n;i++){
std::cin >> c;
da[i]=c;
dp[i]=dp[i-1];
if(da[i]!=da[i-1]){
dp[i]=(co[c-1]+dp[i])%1000000007;
co[c-1]=(dp[i... | 0 |
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int pri[1010],wai[1010],dp[2][1010];
int main(){
int W,N,cas=0;
while(true){
cas++;
cin>>W;
if(W==0) break;
cin>>N;
for(int i=1;i<=N;i++){
scanf("%d,%d",&pri[i],&wai[i]);
}
fill(dp[0],dp[0]+W+1,0);
fill(dp[1],dp[1]+W+1... | 0 |
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
using namespace std;
int main()
{
ll n,m,k,i,j;
cin>>n>>m>>k;
for(i=0;i<=n;i++)for(j=0;j<=m;j++)if(i*m+j*n-2*i*j==k)
{
cout<<"Yes";return 0;
}
cout<<"No";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[100000], n, k, S;
int b[100000], t;
long long f(long long x) {
long long res = 0;
for (int i = 0; i < (int)(n); i++)
if (a[i] <= x)
res += a[i];
else
res += x;
return res;
}
int main() {
scanf("%I64d%I64d", &n, &k);
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int get(int f, int s) {
if(s < 0) return 1;
int ret = 0;
int d[10] = {0};
for(int i = f; i < N-s; i++) {
int c = S[i] - '0';
if(d[c]) continue;
d[c]++;
ret += get(i+1, s-1);
}
return ret;
}
int main()... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
std::cin >> n;
std::vector<std::pair<int, int>> r(n);
std::vector<std::pair<int, int>> b(n);
for (auto &i : r) {
std::cin >> i.second >> i.first;
}
for (auto &i : b) {
std::cin >> i.first >> i.second;
}
std::sort(r.begin(), r.end());
std::sor... | 0 |
#include <bits/stdc++.h>
using namespace std;
void dv(vector<long long int> g1) {
for (auto i = g1.begin(); i != g1.end(); ++i) {
cout << *i << " ";
}
}
int invert(int a) {
if (a == 0) {
return 1;
} else if (a == 1) {
return 0;
} else {
return -1;
}
}
long long int fact(long long int n) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int const N = 100001;
int n, q, h[N], en[N], ex[N], cm, fm[N], pa[N][18], lg[N], mxl;
vector<vector<pair<int, int> > > x;
vector<int> tr[N], f;
int t = 0;
void pl(int v, int p = 0, int hi = 0) {
en[v] = ++t;
h[v] = hi;
fm[v] = cm;
pa[v][0] = p;
for (int i = 1; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
struct edge {
int to, cap, cost, rev;
edge(int to_, int cap_, int cost_, int rev_):to(to_), cap(cap_), cost(cost_), rev(rev_) {}
};
constexpr int INF = (1 << 29);
int V;
vector<vector<edge>> G;
vector<int> h;
vector<int> dist;
vector<int> pre... | 0 |
#include <bits/stdc++.h>
const int N = 1e5 + 5;
int n, m;
struct Chairman {
static const int M = 20 * N;
int idx, rt[N], ls[M], rs[M], val[M];
void modify(int &p, int l, int r, int u, int x, int v) {
p = ++idx, ls[p] = ls[u], rs[p] = rs[u], val[p] = std::max(val[u], v);
if (l == r) {
return;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<bool> level;
for (int i = 0; i < n; ++i) {
char temp;
cin >> temp;
if (temp == '*')
level.push_back(true);
else
level.push_back(false);
}
for (int i = 0; i < n; ++i) {
for (int j = 1; j < (n - ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 1e9 + 7;
const long long maxn = 1e6 + 107;
const double pi = acos(-1.0);
const double eps = 0.0000000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
t... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
printf("%d\n", n);
for (int i = 1; i <= n; i++) printf("%d ", i);
puts("");
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50;
int a[maxn], b[maxn - 1];
const int maxl = 51;
long long d[maxn][maxl];
long long whole[maxl];
void solve(int *a, int n, int pmin, int pmax) {
memset(d, 0, sizeof(d));
d[0][0] = 1;
for (int it = 0; it < n; it++) {
for (int taken = it; taken >=... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, k, i;
cin >> n >> m >> k;
long long int a[m];
for (i = 0; i < m; i++) {
cin >> a[i];
}
long long int cnt = 0;
long long int ans = 0;
for (i = 0; i < m;) {
long long int c = (a[i] - cnt - 1) / k;
long long int j = ... | 1 |
#include<bits/stdc++.h>
using namespace std;
int n,a,b,sum;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a>>b;
sum+=b+1-a;
}
cout<<sum;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n;
long long int h;
int main() {
cin >> n;
h = (n - 2) * (n - 2);
cout << h << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long n, q, bs;
long long input[2000000];
long long ans[2000000];
unordered_map<long long, long long> cnt;
struct query {
long long L, R, indx;
} arr[2000000];
bool cmp(const quer... | 2 |
#include <bits/stdc++.h>
long long a[30], num[(1 << 20) + 1];
int f[(1 << 20) + 1], g[(1 << 20) + 1], lg[(1 << 20) + 1], ppc[(1 << 20) + 1];
int main() {
register int n, ans = 0;
scanf("%d", &n);
for (register int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (a[i] == 0) n--, i--;
}
lg[0] = -1;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n;
cin >> n;
int i, a[n];
for (i = 0; i < n; ++i) cin >> a[i];
int z = a[0], st = a[0], maxm = 0, l = 1;
for (i = 1; i < n; ++i) {
if (a[i] == abs(1 - z)) {
l++;
z = a[i];
} else {
if (st != z && st == 0)... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int K = 26;
struct vertex {
vector<int> next;
int cnt;
vertex() : next(K, -1), cnt(1) {}
};
vector<vertex> trie;
vector<vector<pair<int, char>>> graph;
vector<int> sz;
vector<int> height;
void init_dfs(int v, int h = 0) {
sz[v] = 1;
height[v] = h;
for (aut... | 6 |
#include <bits/stdc++.h>
using namespace std;
string F[100010];
char str[1000];
int T[100010], e;
set<string> A, B, AB, BA, FA, FB;
vector<pair<string, string> > ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s%d", str, T + i);
F[i] = string(str);
if (T[i] == 1) e++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> day_seq;
vector<int> main_seq;
int sec, mn, hr, dw, dm, month;
int mlen[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
cin >> sec >> mn >> hr >> dw >> dm >> month;
if (dw > 0) --dw;
if (dm > 0) --dm;
if (month > 0) --month;
int ct... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
sort(a.begin(), a.end());
queue<int> current;
int res = 0;
for (int i = 0; i < n; ++i) {
if (current.size() !=... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const long double eps = 1e-12;
int cmp(long double a, long double b) {
if (fabs(a - b) <= eps) return 0;
return (a > b) ? 1 : -1;
}
struct P {
long double x, y;
P() {}
P(long double X, long double Y) { x = X, y = Y; }
P operato... | 4 |
#include<iostream>
using namespace std;
int main(){
int n;
int cnt;
while(1){
cin>>n;
if(n==0)break;
cnt=0;
while(1){
if(n==1)break;
if(n%2==0){
n=n/2;
cnt++;
}
if(n%2!=0&&n!=1){
n=n*3+1;
cnt++;
}
}
cout<<cnt<<endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
class LazySegmentTree
{
public:
LazyS... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAX = 1e17 + 7;
const ll N = 1e5+7;
struct aa{
ll u,d;
bool operator < (const aa & a) const{
return d>a.d;
}
};
vector<aa>arr[N];
bool vis[N];
ll n,m;
ll d[N];
void Dij(){
fill(d+1,d+n+1,MAX);
d[1]=0;
priorit... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[5][5], i, j;
for (i = 0; i < 5; i++)
for (j = 0; j < 5; j++) {
cin >> a[i][j];
if (a[i][j] == 1) cout << abs(2 - i) + abs(2 - j);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long double PI = acosl(-1);
bool compare_int(int a, int b) { return (a > b); }
bool compare_string(string a, string b) { return a.size() < b.size(); }
bool compare_pair(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second == b.second)
return a.first > b.fi... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 8e4 + 5;
long long n, res, countTwice;
long long sz[N];
bool vis[N];
vector<vector<long long> > v(N);
inline long long F(long long x) { return (x * (x - 1)) >> 1; }
void dfs(long long node) {
vis[node] = true;
sz[node] = 1;
long long pathsHere = 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int x = 0;
string op;
char arr[1000][1000];
bool put = true;
int counter = 0;
vector<string> vs;
if ((a >= 1) && (a <= 1000)) {
int i, j;
for (int i = 0; i < a; i++) {
string s;
for (int j = 0; j < a; j++) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
;
int ans = 0;
int x[1100], y[1100];
bool right, left, up, down;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i == j) continue;
if (x[j] > x[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, N = 1e3 + 10, P = 1e9 + 7;
template <class T>
inline bool chkmin(T &A, T B) {
return B < A ? A = B, 1 : 0;
}
template <class T>
inline bool chkmax(T &A, T B) {
return A < B ? A = B, 1 : 0;
}
template <class T, class _>
inline void Add(T &firs... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
vector<int> v;
int father[maxn][2];
int rk[maxn][2];
int sz[maxn][2];
int Find(int v, int t) {
return father[v][t] = father[v][t] == v ? v : Find(father[v][t], t);
}
void merge(int x, int y, int t) {
int a = Find(x, t), b = Find(y, t);
if... | 4 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int cnt1 = 0, cnt2 = 0;
void ReadInput() { cin >> a >> b; }
void Solve() {
for (int i = 0; i < a.size(); i += 2) {
if (a[i] == '[' && a[i + 1] == ']') {
if (b[i] == '(' && b[i + 1] == ')') cnt1++;
if (b[i] == '8' && b[i + 1] == '<') cnt2++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef struct man {
int num;
int sum;
} man;
int n, t1, t2, sale;
int s[1000][2];
man m[1000];
int cmp(man a, man b) {
if (a.sum == b.sum) {
return a.num < b.num;
}
return a.sum > b.sum;
}
int main() {
int i, j;
cin >> n >> t1 >> t2 >> sale;
sale = 100 ... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.