solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<int> col[300005];
vector<int> graph[300005];
int ans[300005];
void dfs(int t, int p) {
set<int> used;
int last = 1;
for (int x : col[t]) {
if (ans[x]) used.insert(ans[x]);
}
for (int x : col[t]) {
if (ans[x]) continue;
while (used.count(last)) +... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
struct BITree {
int n, bit[N];
int lowbit(int x) { return x & -x; }
void modify(int x, int d) {
for (; x <= n; x += lowbit(x)) bit[x] += d;
}
int query(int x) {
int ans = 0;
for (; x; x -= lowbit(x)) ans += bit[x];
return ans... | 3 |
#include <iostream>
#include <vector>
using namespace std;
int n, q;
vector<vector<int>> d;
vector<long long> c;
void add(int p) {
for (int i = 0; i < d[p].size(); i++) {
c[d[p][i]] += c[p];
add(d[p][i]);
}
}
int main()
{
cin >> n >> q;
d.resize(n + 1);
c.resize(n + 1, 0);
for (int i = 0; i < n - 1; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
if (n > 1001)
cout << "0";
else {
long long mul = 1;
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a == b) {
cout << a;
} else if (a != b) {
cout << 1;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int ix, iy;
void Set(char ch) {
if (ch == 'R') {
ix = ix + 1;
}
if (ch == 'L') {
ix = ix - 1;
}
if (ch == 'U') {
iy = iy + 1;
}
if (ch == 'D') {
iy = iy - 1;
}
}
int main() {
int t, n;
string s;
scanf("%d", &t);
while (t--) {
scan... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
char str[MAXN];
int num[1<<26];
int dp[MAXN];
int sum;
int main()
{
scanf("%s", str);
memset(num, 0x3f, sizeof(num));
memset(dp, 0x3f, sizeof(dp));
num[0]=0;
sum=0;
int len=strlen(str);
for(int i=0;i<len;++i)
{
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long l, t, w, ans = 0;
long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
int main() {
ios::sync_with_stdio(false);
cin >> l >> t >> w;
long long c = lcm(t, w);
lo... | 3 |
#include <bits/stdc++.h>
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& v) {
for (T& a : v) input >> a;
return input;
}
void answer(unsigned long long v) { std::cout << v << '\n'; }
void solve(std::vector<int>& a) {
const size_t n = a.size();
std::sort(a.begin(), a.end(), st... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int ans, cnt;
int check() {
int res = 0;
for (int i = 0; i < (int)s.length() - 1; i++) {
if (s[i] == 'V') {
if (s[i + 1] == 'K') {
res++;
i++;
}
}
}
return res;
}
int main() {
cin >> s;
ans = max(ans, check());
for... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int infinito = 1000000000000000000LL;
long long int propagax(long long int antx, long long int anty, long long int dx,
long long int dy, char v[10]) {
long long int sol;
if (dx >= dy) {
if (antx == 0) return 0;
if (antx % 2 == 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 258280327;
int a, b, c, Val[1000006], ans;
int main() {
for (int i = 1; i != 1000006; ++i)
for (int j = i; j < 1000006; j += i) ++Val[j];
scanf("%d %d %d", &a, &b, &c);
for (int i = 1; i <= a; ++i)
for (int j = 1; j <= b; ++j)
for (int k =... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long A[1005], B[1005];
long long dp[1005][1005];
vector<long long> G[1005], g[1005];
vector<pair<long long, pair<long long, long long> > > V;
long long weight, beauty;
int vis[1005];
void dfs(int u, int root) {
g[root].push_back(u);
vis[u] = 1;
weight += A[u];
... | 4 |
#include <bits/stdc++.h>
const int MAXN = 1010;
using namespace std;
int a[MAXN];
bool dp[MAXN][MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
if (n >= m) {
cout << "YES\n";
return 0;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = a[i] % m;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int N, M;
cin >> N >> M;
vector<pair<int, int>> S(N), C(M);
for (auto &p : S) {
cin >> p.first >> p.second;
}
for (auto &p : C) {
cin >> p.first >> p.second;
}
for (auto s : S) {
int d = 1e9, ans;
for (in... | 0 |
#include<bits/stdc++.h>
using namespace std;
long long i,j,n,m,a[3],b,c,d,k;
string s,x,y;
int main()
{
cin>>a[0]>>a[1]>>a[2]>>k;
sort(a,a+3);
cout<<a[0]+a[1]+a[2]*pow(2,k);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int S[10005], jump[10005], Max[10005][105], Min[10005][105];
int Plus, Minus, m, small, big, tot;
char a[10005];
int DFS(int l, int r) {
int x = ++tot;
if (l == r) {
Max[x][0] = Min[x][0] = a[l] - '0';
return x;
}
int _ = a[l + 1] == '(' ? jump[l + 1] + 1 : ... | 5 |
//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#defi... | 6 |
#include <bits/stdc++.h>
using namespace std;
int q[111], a[111 + 111][111], qq[111], b1, b2, res[111];
int main() {
int i, j, k, n;
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> q[i];
qq[q[i]] = i;
}
for (i = 1; i <= n; i++) cin >> res[i];
for (i = 1; i <= n; i++) a[111][i] = i;
b1 = b2 = 111;... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline void priv(vector<int> a) {
for (int i = 0; i < ((int)(a).size()); ++i)
printf("%d%c", a[i], i == (int)(a).size() - 1 ? '\n' : ' ');
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v)... | 2 |
#include <cstdlib>
#include <cstdarg>
#include <cassert>
#include <cctype> // tolower
#include <ctime>
#include <cmath>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <string>
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,r;
cin>>n>>r;
cout<<r+100*(10-min(n,10))<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int p, x, y;
bool foo(int s) {
int res = (s / 50) % 475;
for (int i = 0; i < 25; i++) {
res = (res * 96 + 42) % 475;
if (res + 26 == p) return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(0);
cin >> p >> x >> y;
int t = x;
while (t ... | 2 |
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
template <typename T, size_t N>
using ar = array<T, N>;
#define INF (numeric_limits<int>::max())
#define INFLL (numeric_limits<ll>::m... | 4 |
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
... | 0 |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top, S[10000];
void push(int x)
{
S[++top] = x;
}
int pop()
{
top--;
return S[top + 1];
}
int main()
{
int a, b;
top = 0;
char s[100];
while(scanf("%s", s) != EOF)
{
if(s[0] == '+'){
a = pop();
b = pop();
push(a + b);
}else if(s[0]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t = 1;
cin >> t;
while (t--) {
vector<string> v;
for (int i = 0; i < 9; i++) {
string g;
cin >> g;
v.push_back(g);
}
for (int i = 0; i < 9; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17 + 9;
long long n;
long long mult(long long a, long long b) { return a * b % n; }
long long fastpow(long long a, long long b) {
long long calc = 1;
for (; b >= 1LL; b /= 2LL) {
if ((b & 1LL)) calc = mult(calc, a);
a = mult(a, a);
}
... | 5 |
#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) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long lazy_state[4][4] = {
{0, 1, 2, 3}, {1, 0, 2, 3}, {2, 3, 2, 3}, {3, 2, 2, 3}};
int curr = 1;
struct Ver... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 9;
const int maxn = 2e5 + 7;
const int maxm = 1e7 + 7;
int P[maxn], Q[maxn], m, n;
bool check(int x) { return x != -1e9 - 1; }
int main() {
scanf("%d", &n);
long long preP = -1e9 - 1, preR = -1e9 - 1, preB = -1e9 - 1;
long long maxB = 0, maxR = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int a[20], n, primecount, primes[20];
vector<long long int> tree;
long long int comp(long long int curr, long long int rootChildrenNum,
long long int totalBranchCount) {
if (curr == n)
return rootChildrenNum + (totalBranchCount > 1) + n - ... | 3 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
#include<stdio.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
int... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
const long long MOD = 1e9 + 7, INF = 1e9 + 10;
string s;
long long ans = 1;
int main() {
cin >> s;
for (int i = 0; i < (int)s.size(); i++) {
int tmp;
if (s[i] >= 'A' && s[i] <= 'Z') tmp = 10 + s[i] - 65;
if (s[i] >= ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long sum = 1;
while (y--) {
sum *= x;
}
return sum;
}
string decToBinary(int n) {
string s = "";
for (int i = 31; i >= 0; i--) {
int k = n >> i;
if (k & 1) {
s += "1";
} else {
s += "0"... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int B_found = 0, n, m, mni = 200, mnj = 200, mxi = -1, mxj = -1, mxlength = 0,
mnlength = 0, cnt = 0, i, j;
char a[200][200];
cin >> n >> m;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cin >> a[i][j];
if (a[i][j] == 'B') ... | 2 |
#include <bits/stdc++.h>
int i, j, k, n, t;
bool prime(int p) {
if (p < 4) return 1;
for (int l = 2; l * l <= p; l++) {
if (p % l == 0) return 0;
}
return 1;
}
void F() {
bool z = 0;
for (i = 2; i * i / 2 <= t; i++) {
if (prime(i) && prime(t - i)) {
printf("2\n%d %d\n", i, t - i);
z = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e18;
int n, m, S, T;
long long L;
struct Edge {
int fr, to;
int id;
int next;
} e[10010 * 2];
int wall[10010];
long long len[10010];
int head[1010];
int ne;
void add(int a, int b, int id) {
int t = ne++;
e[t].fr = a;
e[t].to = b;
e[t].id... | 2 |
#include<map>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
multimap<string, int> mp;
while (T--) {
int t;
cin >> t;
if (t==0) {
string s;int a;
cin >> s >> a;
mp.insert(pair<string ,int >(s, a));
... | 0 |
#include <bits/stdc++.h>
int main(int argc, char** argv) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T;
std::cin >> T;
for (int q = 0; q < T; q++) {
std::string y, x;
std::cin >> x >> y;
std::reverse(y.begin(), y.end());
std::reverse(x.begin(), x.end());
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int cnt[3005];
char ans[3005];
vector<int> vis1[105], vis2[105];
vector<string> edge1[105], edge2[105], edge3[105];
void solve(int n) {
cout << "?"
<< " " << 1 << " " << n << endl;
cout.flush();
for (int i = 1; i <= ((1 + n) * n / 2); i++) {
string s;
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int bs1(int a) {
int inicio = 1, fin = n, med = (inicio + fin) / 2, x;
while (inicio < fin) {
med = (inicio + fin) / 2;
cout << '?' << ' ' << a << ' ' << inicio << ' ' << a << ' ' << med << '\n';
cout.flush();
cin >> x;
if (x & 1) {
fin ... | 5 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
using namespace std;
#def... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n, i, j;
string s, ans = "";
cin >> n >> k;
cin >> s;
vector<int> in[26], a(n, 0);
for (i = 0; i < n; i++) {
in[s[i] - 'a'].push_back(i);
}
for (i = 0; i < 26; i++) {
if (k == 0) break;
for (j = 0; j < in[i].size(); j++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
struct node {
int to;
long long cst;
};
vector<node> eg[200005];
int sz[200005], vis[200005];
int k;
long long g, b;
void dfs(int x) {
vis[x] = 1;
for (node &i : eg[x]) {
if (vis[i.to]) continue;
dfs(i.to);
s... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
out << v[i] << " ";
out << "\n";
return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<p... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e3 + 10;
const long long MXM = 5e2 + 10;
const long long MX5 = 1e5 + 10;
const long long MX6 = 1e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long lo... | 3 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
long long int sum[9];
int main(void)
{
char name[10];
int toku[9][9],n,make,kati,hiki,touroku[9];
int flg[10];
while(1) {
cin>>n;
if(n==0) break;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll>pll;
const int mod = 1e9 + 7;
int maxiK;
int factor;
void primeFactorization(ll n) {
// cout << "Here" << endl;
vector<pll>val;
maxiK = 1;
factor = n;
for (... | 4 |
// 基本テンプレート
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i = 0, j = 0, k = 0, l = 0, m, n, s = 0, x = 0, y = 0, d;
string st, an = "", bn = "", cn = "";
cin >> st;
for (i = 0; i < st.length();) {
if (st[i] == '0') {
an += '0';
i++;
} else if (st[i] == '1') {
j = i + 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, M, D;
cin >> a >> b >> c >> d;
M = max((3 * (a / 10)), (a - (a / 250) * c));
D = max((3 * (b / 10)), (b - (b / 250) * d));
if (M > D) {
cout << "Misha";
} else if (D > M) {
cout << "Vasya";
} else {
cout << "Tie";
}
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9 + 1;
constexpr long long LLINF = 1e18 + 1;
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
pair<int, int> cmp(string guess, string corr) {
pair<int, int... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> arr(n);
for (long long int i = 0; i < n; ++i) {
long long int x;
cin >> x;
arr[i] = x;
}
vector<vector<long long int> > ans;
for (long long int i = n - 1; i >= 0; --i) {
long long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
int n;
cin >> n;
long long ans = 0;
for (int i = 1; i <= n; i++)
{
ans += i * (long long)(n / i + 1) * (n / i) / 2;
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
signed main() {
cin.tie(0);
ios::s... | 1 |
#include <bits/stdc++.h>
using namespace std;
string A;
int i, j;
int main() {
int countc[26] = {0};
cin >> A;
char maX = 'a';
int idx = 0;
for (i = 0; i < A.size(); i++) {
if (A[i] > maX) {
maX = A[i];
idx = i;
}
}
int start = idx;
for (i = maX; i >= 'a'; i--) {
start = idx;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a;
cin >> n >> m;
if (2 * m <= n) {
a = m + 1;
if (a > n) a = n;
} else {
a = m - 1;
if (a < 1) a = 1;
}
cout << a << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int a, b, c, d, e;
};
node nod[111];
int main() {
int n, i, j, k;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d%d%d", &nod[i].a, &nod[i].b, &nod[i].c, &nod[i].d);
nod[i].e = 1;
}
for (i = 0; i < n; i++) {
if (nod[i].e) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int k;
void makeMax(int pos) {
int steps = 0;
int digit = s[pos];
int len = s.size();
int j = pos;
for (int i = pos; i < len && steps <= k; i++, steps++) {
if (s[i] > s[j]) {
j = i;
}
}
for (int i = j; i > pos; i--) {
char temp = s[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, k, h0, h1;
scanf("%d %d %d %d", &n, &m, &k, &h0);
bool res = true;
--n;
while (n--) {
scanf("%d", &h1);
if (h0 + m + k < h1) {
while (getchar() != '\n') {
};
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int> > ed(n + 1);
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
ed[a].push_back(b), ed[b].push_back(a);
}
s... | 2 |
#include <bits/stdc++.h>
using namespace std;
stack<long long int> S;
int main() {
long long int n, num = 0, tmp, ans = 0, pos, plis = 0;
cin >> n;
for (long long int i = 0; i < n; ++i) {
cin >> tmp;
plis += 1;
S.push(i);
while (tmp > num - 1) {
pos = S.top();
S.pop();
num += 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct LBCTaiQiangLe {
int fa[1000005], v[1000005], id[1000005], n;
void init(int x) {
n = x;
for (int i = 1; i <= n; i++) fa[i] = id[i] = i;
}
int get(int x) {
if (fa[x] == x) return x;
int t = get(fa[x]);
v[x] = max(v[x], v[fa[x]]);
return ... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void check_min(T& a, T b) {
if (b < a) a = b;
}
template <class T>
inline void check_max(T& a, T b) {
if (a < b) a = b;
}
const int MAX_N = 100100;
const long long INF = 1e16;
int n, k, a[MAX_N];
map<long long, int> mp;
vector<long long> ps;
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool check[1000];
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, mini, maxi;
cin >> n >> m >> mini >> maxi;
vector<int> accum;
int take = n - m;
while (m--) {
int x;
cin >... | 1 |
#include <bits/stdc++.h>
using namespace std;
int H, W;
int A[400][400];
short dp[400][400][400];
int m[160001];
int lp[160001];
int main() {
scanf("%d%d", &H, &W);
for (int(i) = 0; (i) < (H); (i)++)
for (int(j) = 0; (j) < (W); (j)++) scanf("%d", &A[i][j]);
for (int(i) = 0; (i) < (H); (i)++)
for (int(j) =... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool used[200001];
int pc[500001];
vector<int> d[200001];
long long c[500001];
void init() {
int i, j;
pc[1] = 1;
for (i = 1; i <= 500000; i++)
for (j = i << 1; j <= 500000; j += i) pc[j] -= pc[i];
}
int main() {
int n, q, i, j, x, tmp;
long long ans = 0;
sc... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void rd(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void pp(T... args) {
((cout << args << " "), ...);
cout << "\n";
}
void solve() {
long long int n, k;
rd(n, k);
vector<long long int> x(n), y(n);
for (long long int... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
return a < b ? (a = b, true) : false;
}
const long long P = 1000000000 + 7;
const double PI = atan2(0, -1);
void fft(vector<complex<double> > &a, bo... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[300005], ind[300005], ans[300005];
map<long long, long long> mp;
vector<pair<pair<long long, long long>, long long> > v;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(0);
};
long long j = 1, k, t, n, m, cnt = 0, l = 0, r, i, p;
cin >> ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool uax(T &x, T y) {
return (y > x) ? x = y, true : false;
}
template <typename T>
inline bool uin(T &x, T y) {
return (y < x) ? x = y, true : false;
}
void err(istream_iterator<string>) {}
template <typename T, typename... Args>
void err(i... | 6 |
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
#include <bitset>
using namespace std;
int main()
{
vector<int> seg {0b0111111,0b0000110,0b1011011,0b1001111,0b1100110,0b1101101,0b1111101,0b0100111,0b1111111,0b1101111};
int n;
... | 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 ans = 0;
while (n--) {
int x, y;
cin >> x >> y;
ans = max(ans, x + y);
}
cout << ans;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long int, vector<long long int>, greater<long long int> > t;
vector<long long int> p[200005], b(2000005, 0), d(200005, 0);
map<pair<long long int, long long int>, long long int> mp;
set<pair<long long int, long long int> > q;
vector<char> s;
long long in... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, m, n) for (int i = m; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG
signed main() {
int N; cin >> N;
vector<pair<int,int>> x(N);
rep(i, N) cin >> ... | 0 |
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
string s;
int f1[1000005],f2[1000005];
int main(void){
cin>>s;
int n=s.size();
memset(f1,0x3f,sizeof(f1));
memset(f2,0x3f,sizeof(f2));
f1[0]=min(s[0]-'0',11-(s[0]-'0'));
f2[0]=min(s[0]-'0'+1,10-... | 0 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> a >> b;
vector<int> ops1, ops2;
a += '0';
b += '0';
for (int i = 1; i <= n; i++) {
if (a[i] != a[i - 1]) ops1.push_back(i);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
long long int n = 0, preproc[110000], dp[110000], sum[110000], ans[110000],
finans = 0;
vector<int> matches;
void Proc() {
int i = 0, j = -1;
preproc[0] = -1;
while (i < t.size()) {
while (j >= 0 and t[i] != t[j]) j = preproc[j];
i++... | 2 |
#include <iostream>
using namespace std;
int main(){
int N;
cin>>N;
int a[N],count=0;
for(int i=0;i<N;i++){
cin>>a[i];
while(a[i]%2==0){
count++;
a[i]/=2;
}
}
cout<<count<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve(string s) {
int l = s.length();
string az = "abcdefghijklmnopqrstuvwxyz";
char c = 'a';
int curr = (int)c;
string ans;
int i;
int z = (int)'z';
int fa = 0;
for (i = 0; i < l; i++) {
int sc = (int)s[i];
if (sc > curr) {
ans += s[i];... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (s == "0") {
cout << "0" << endl;
return 0;
}
int cnt = 0;
for (char c : s) {
if (c == '0') {
cnt++;
}
}
cout << '1';
for (int i = 0; i < cnt; i++) cout << '0';
cout << endl;
... | 1 |
#include<stdio.h>
int main()
{
int n,i,s,m;
scanf("%d",&n);
m=n;
s=0;
while(n)
{
s+=n%10;
n=n/10;
}
if(m%s==0)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
return 0;
} | 0 |
/*
数据不清空,爆零两行泪。
多测不读完,爆零两行泪。
边界不特判,爆零两行泪。
贪心不证明,爆零两行泪。
D P 顺序错,爆零两行泪。
大小少等号,爆零两行泪。
变量不统一,爆零两行泪。
越界不判断,爆零两行泪。
调试不注释,爆零两行泪。
溢出不 l l,爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define X first
#define Y second
#define pb push_back
#define ppb pop_back
int n,x,d;
map<in... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100003], y[100003];
vector<pair<int, int> > res;
vector<int> vec;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
int cnt = n;
for (int i = n; i >= 1; i--) {
if (a[i] == 1) {
y[i] = cnt--;
res.emplace_back(... | 4 |
#include <iostream>
#include <string>
using namespace std;
int b[100][100], n, m;
int xx[4] = {-1, 0, 0, 1}, yy[4] = {0, -1, 1, 0};
int solv(int g[100][100], int y, int x, char c){
if(y < 0 || x < 0 || n <= y || m <= x)return 0;
if(c == 'a')c = g[y][x];
if(b[y][x] || g[y][x] != c)return 0;
b[y][x] = 1;
for(int i ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<set<int>> con(n + 1);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
con[a].insert(b);
con[b].insert(a);
}
vector<bool> used(n + 1, false);
int ans = 0;
for (int i = 1; i <= n; ++i) {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 999999999;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;
long long n;
vector<long long> a;
long long idx[100005], cnt[100005];
long long ans[100005];
long long mod_pow(long long b, long long e) {
long long r = 1, q = b;
while... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int b[200005];
vector<int> a;
cin >> n;
a.push_back(31);
a.push_back(28);
a.push_back(31);
a.push_back(30);
a.push_back(31);
a.push_back(30);
a.push_back(31);
a.push_back(31);
a.push_back(30);
a.push_back(31);
a.push_back(30... | 2 |
#include <iostream>
#include <vector>
using namespace std;
#define MAX 7368792
int main() {
int m, n;
while (cin >> m >> n, m) {
vector<bool> used(MAX);
int ans = m;
for (int i = 0; i < n; ++i) {
for (int j = ans; j < MAX; j += ans) used[j] = true;
while (used[ans]) ++ans;
}
cout << ans << endl;
}... | 0 |
#include <bits/stdc++.h>
int f[10] = {0}, t, g[10] = {0}, ans, l;
char s[210];
int main() {
scanf("%d%s", &t, s);
l = strlen(s);
for (int i = 0; i < l; i++) f[s[i] - '0']++;
f[2] += f[5];
f[5] = 0;
f[6] += f[9];
f[9] = 0;
while (t) {
g[t % 10]++;
t /= 10;
}
g[2] += g[5];
g[5] = 0;
g[6] +... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
srand(time(0));
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
const long long N = 2e5 + 100, M = 6e5 + 100, Q = 5e5 + 100, K = 40, INF = 1e18,
MOD = 998244353;
long long t, n, m, dp[N][2];
vecto... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 10;
vector<int> vec[maxn];
vector<int> ans;
stack<int> st;
int pa[maxn];
int deg[maxn];
int vis[maxn];
void dfs(int u, int pre) {
pa[u] = pre;
st.push(u);
for (int i = 0; i < vec[u].size(); i++) {
int t = vec[u][i];
if (t == pre) con... | 2 |
#include<iostream>
using namespace std;
typedef long long ll;
const int N = 100;
int cost[N][N][4];
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};
string op="NESW";
char m[N][N];
void solve(int r,int c,int y,int x,int d,ll step){
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
for(int k=0;k<4;k++)cost[i][j][k]=-1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100;
const double pi = acos(-1.0);
int s[64], num[64];
int r[64];
bool vis[64];
int Find(int x) {
if (x != s[x]) s[x] = Find(s[x]);
return s[x];
}
void Union(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y) return;
if (r[x] > r[y]) {
s[y] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
string s;
cin >> s;
string ans = "";
long long int co = 0;
for (long long int i = 0; i < n; i++) {
if (ans.size() % 2 == 0) {
ans += s[i];
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b, g, n, mxb, mnb;
scanf("%d %d %d", &b, &g, &n);
mxb = min(n, b);
mnb = n - min(g, n);
cout << mxb - mnb + 1 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s,t;
cin >> s;
for(int i=0;i<s.size();i++){
if(s.at(i)=='B'){
if(t!=""){
t.pop_back();
}
}else{
t+=s.at(i);
}
}
cout << t << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 0.001;
const long double EPS2 = 1e-6;
const long double PI = acos(-1);
int mod = (int)998244353;
const int MOD7 = 1000000007;
const int MOD9 = 1000000009;
const int a228 = 18;
const int inf = 1e9;
const long long kekmod = 1791791791;
const long long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return (N | (1 << pos)); }
int fx[] = {-1, 0, 1, 0};
int fy[] = {0, 1, 0, -1};
inline long long BigMod(long long B, long long P, long long M) {
long long R = 1;
while (P > 0) {
i... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.