solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
char s[100006];
int len;
bool end(char ss[]) {
int ll = strlen(ss);
for (int i = len, j = ll; i >= 0 && j >= 0; i--, j--) {
if (s[i] != ss[j]) return false;
if (j == 0) return true;
}
return false;
}
int main() {
bool m = false, fm = false, noun = false, v... | 1 |
#include <bits/stdc++.h>
using namespace std;
class FenwickTree {
public:
explicit FenwickTree(int N) : F(N, 0) {}
void Add(int i, int delta) {
for (; i < F.size(); i = (i | (i + 1))) {
F[i] += delta;
}
}
int Sum(int i) const {
int result = 0;
for (; i >= 0; i = (i & (i + 1)) - 1) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m = 0, i, j = 0, a, h;
cin >> t;
for (i = 1; i <= t; i++) {
cin >> n;
a = n;
if (n == 1)
cout << "0" << endl;
else if (n == 2)
cout << "1" << endl;
else {
while (a >= 2) {
while (n - m > 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct ii {
int first;
int second;
int i;
ii(int a = 0, int b = 0) {
first = a;
second = b;
}
bool operator<(const ii &o) const {
return first == o.first ? second < o.second : first < o.first;
}
};
ii l[300010];
int n, w;
long long A[300010];
int t... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long st(int n) {
long long an = 1;
for (int i = 1; i <= n; i++) an = (an * 3) % 1000000007;
return an;
}
int main() {
cin >> n;
long long v;
if (n % 2 == 0)
v = 3;
else
v = -3;
cout << ((st(n) + v) * 250000002) % 1000000007 << endl;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int U[5005], V[5005];
struct emm {
int a, b, x;
} a[5005];
bool cmp(emm x, emm y) { return x.x < y.x; }
struct Edge {
int v;
Edge *next;
} pool[5005 << 1], *h[5005];
int fa[5005], dep[5005], ans[5005];
int tot;
void addEdge(int u, int v) {
Edge *p = &pool[... | 6 |
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int n,bad[100000],deg[100000],ans[100000];
set<int> V; // unused vertices (and a centinel)
set<pair<int,int>> Deg; // (degree, vertex)
bool dfs(int i){
if(i==n) return true;
int x=Deg.rbegin()->second;
if(deg[x]==n-i-1){
if... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n == 2) {
cout << "1\n0\n";
continue;
}
vector<long long> a = {1};
long long s = 1;
while (s < n) {
a.push_... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin>>t;
while (t--)
{
long long x,y;
cin>>x>>y;
string s;
cin>>s;
long long r=0;
long long l=0;
long long u=0;
long long d=0;
for (long... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#de... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> p, in_time, out_time, level;
vector<vector<long long> > g;
long long k;
void dfs_time(long long node, long long parent, long long l) {
in_time[node] = k++;
p[node] = parent;
level[node] = l;
for (auto i : g[node]) {
if (i != par... | 5 |
#include <bits/stdc++.h>
using namespace std;
char arr[505][505];
int dp[505][505];
int dpv[505][505];
int main() {
ios::sync_with_stdio(0);
int q, i, j, k, l, r, c, x, y, r1, c1, r2, c2, ans;
cin >> r >> c;
for (i = 1; i <= r; i++) {
for (j = 1; j <= c; j++) {
cin >> arr[i][j];
}
}
dp[1][1] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool comp(int x, int y) { return x > y; }
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
int a[n + 1];
for (int k = 1; k <= n; k++) cin >> a[k];
sort(a + 1, a + 1 + n, comp);
for (int k = 1; k <= n; k++) {
cout << a[k] << ' ';
}... | 2 |
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <stdint.h>
std::vector<int64_t> edges[100005];
int64_t as[100005];
void fail(){
printf("NO\n");
exit(0);
}
int64_t dfs(int64_t node,int64_t parent){
if(edges[node].size()==1&&node!=parent) return as[node];//leaf
int64_t ac=0;
int64_t max=0;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N; cin>>N;
N=1<<N;
vector<int> a(N);
for(int i=0;i<N;i++) cin>>a[i];
while(a.size()>1){
vector<int> b;
for(int i=0;i<a.size();i+=2){
if(a[i]==a[i+1]) b.push_bac... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x[100002] = {0}, j, t;
cin >> n;
t = n;
for (int i = 0; i < n; i++) {
cin >> j;
x[j] = 1;
while (t >= 1 && x[t] == 1) {
cout << t << " ";
t--;
}
cout << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,a=99;
cin >> N;
for(int i=1; i<N; i++){
int e=100000,f=0;
for(; e!=1; e=e/10){
f+=i%e/(e/10)+(N-i)%e/(e/10);
}
a=min(a,f);
}
cout << a << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int n, a, b;
void f(int in, vector<int> cur) {
vector<int> temp;
int p, q;
for (int i = 0; i < cur.size(); i += 2) {
p = cur[i];
q = cur[i + 1];
if (p == a && q == b) {
if (cur.size() == 2)
printf("Final!\n");
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
char s[N][N];
int sum[N][N];
int get_sum(int x1, int y1, int x2, int y2) {
return sum[x2][y2] - sum[x2][y1 - 1] - sum[x1 - 1][y2] + sum[x1 - 1][y1 - 1];
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
memset(sum, 0, sizeof(sum));
for (int i = 1... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int z;
long double a,b;
cin>>a;
cin>>b;
if(a>b)
cout<<"GREATER";
else if(b>a)
cout<<"LESS";
else
cout<<"EQUAL";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int i, j, k, n, t, m1, m2, p, q;
cin >> t;
while (t--) {
cin >> k >> n;
p = min(k, n);
q = max(k, n);
m1 = q - p;
m2 = (2 * p - q) * 2 / 3;
if (q >= 2 * p)
cout << p << endl;
else
cout << m1 + m2 << endl;
}
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long qpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b % 2 != 0) ans *= a;
ans %= mod;
a = (a * a) % mod;
b /= 2;
}
ans %= mod;
return ans;
}
int main() {
long long x, k;
long long ans;
cin >>... | 3 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <sstream>
#include <string>
using namespace std;
#define FOR(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, j, k, l, sum = 0, flag = 0, t, a[200005], ans = 0, m;
string s;
bool check(int first) {
long long ind = n - first, cnt = 1, cur = k;
for (; ind < n; ind++) {
if (a[ind] > k) return false;
if (a[ind] <= cur) {
cur -= a[ind];
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Tuple {
int l, r, type, i;
} everything[2 * 100005];
bool cmp(Tuple x, Tuple y) {
if (x.l == y.l) {
if (x.type == y.type) {
return x.r < y.r;
} else {
return x.type < y.type;
}
}
return x.l < y.l;
}
int n, m;
int main() {
bool yes;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, g;
int a[10010], v[10010];
struct Node {
int to, next, flow;
} Edge[10010 << 4];
int Head[10010 << 1], cnt_Edge = 1;
void add(int u, int v, int w) {
Edge[++cnt_Edge] = (Node){v, Head[u], w};
Head[u] = cnt_Edge;
}
void Add_Edge(int u, int v, int w) {
add(u,... | 5 |
#include <iostream>
using namespace std;
int main() {
int A, B, C, X, Y;
scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);
printf("%d\n", min(A * X + B * Y, min(2 * C * max(X, Y), 2 * C * min(X, Y) + (X > Y ? A * (X - Y) : B * (Y - X)))));
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i;
string word, s1, s2;
cin >> n >> m;
map<string, string> m1;
for (i = 0; i < m; i++) {
cin >> s1 >> s2;
m1[s1] = s2;
}
for (i = 0; i < n; i++) {
cin >> word;
if (word.length() <= m1[word].length())
cout << word <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> singlefactorise(long long int a) {
set<long long int> salman;
for (int i = 2; i * i <= a; i++) {
while (a % i == 0) {
salman.insert(i);
a /= i;
}
}
if (a != 1) salman.insert(a);
vector<long long int> kaif;
for (set<long ... | 3 |
#include <cstdio>
int main(){
int x;scanf("%d",&x);int y=x;
int s=0;
for(int i=0;i<9;i++){
s+=x%10;x/=10;
}
printf(y%s?"No\n":"Yes\n");
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > neg;
vector<pair<int, int> > pos;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (a < 0) {
neg.push_back({a, b});
} else {
pos.push_back({a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, c = 0, e = 0, f = 0;
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> a[i][j];
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (a[0][0] == a[i][j] && i == j) c++;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
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;
}
int n, a[100100], b, an... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = (int)2e5 + 74, OO = 0x3f3f3f3f, MOD = (int)1e9 + 7;
class CPermutations {
public:
void init() {}
void solve(istream& cin, ostream& cout) {
init();
int n;
cin >> n;
vector<int> a(n), b(n);
map<int, int> idx;
for (int i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, a, b;
vector<pair<int, int>> vp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
vp.push_back(make_pair(a, b));
}
sort(vp.begin(), vp.end());
int ans = 0;
for (int i = 0; i < vp.size(); i++) {
... | 3 |
#include <iostream>
#include <string>
using namespace std;
int main() {
double l[10];
char c;
while(cin >> l[0] >> c) {
// ????????¨??????1?????????
int sum = l[0];
for(int i=1; i<10; i++) cin >> l[i] >> c, sum += l[i];
for(int i=0; i<10; i++) l[i] = l[i]/sum;
// ???????????????1??... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 201;
const long long big = 1e18;
const long long block = 800;
const long long mod = 1e6;
long long n;
long long dp[3];
long long sob[N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
sob[0] = dp[1] = dp[2] = big;
f... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int a[40] = {2, 3, 5, 7, 13, 17, 19,
31, 61, 89, 107, 127, 521, 607,
1279, 2203, 2281, 3217, 4253, 4423, 9689,
9941, 11213... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, i = 0;
stack<char> f;
string n;
cin >> n;
l = n.length();
while (i < l) {
if (f.empty()) {
f.push(n[i]);
} else if (n[i] == f.top()) {
f.pop();
} else {
f.push(n[i]);
}
i++;
}
if (f.empty())
cout ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[200000];
int main() {
int i, j, n, x, y, tec, sqx, kol;
cin >> n;
for (i = 1; i <= n; i++) {
kol = 0;
cin >> x >> y;
sqx = sqrt((double)x) + 2;
for (j = 1; j <= sqx && j < x; j++)
if (x % j == 0) {
if (i - a[j] > y) kol++;
t... | 4 |
#include <bits/stdc++.h>
using namespace std;
void input() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
input();
long long int t;
cin >> t;
while (t--) {
long long int p, f, cnts, cntw, s, w;
cin >> p >> f >> cnts >> cntw >> s >> w;
long long int ans = 0;
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, l, h, mid, num, ind = -1, mn;
cin >> n >> k;
l = 1;
h = k - 1;
while (l <= h) {
mid = (l + h) / 2;
num = (mid * (mid + 1)) / 2 + 1;
if (num >= n) {
ind = mid;
h = mid - 1;
mn = num;
} else if (num < n)... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
sort(s.begin(), s.end());
int n = 1;
for (int i = 0; i < s.length(); i++) {
if (s[i] == s[i + 1]) n++;
}
if (n == s.length()) {
cout << -1 << "\n";
continue... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(name... | 5 |
#include<cstdio>
#include<string>
#include<cstring>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
string solve(const string &s){
int n=s.length();
static int dp[2001][2001],from[2001][2001];
rep(i,n+1) dp[i][0]=dp[0][i]=0, from[i][0]=from[0][i]=-1;
rep(i,n) rep(j,n) if(i+j<=n) {
if(s[i]==s[n-j... | 0 |
#include <bits/stdc++.h>
int parse1(char *s, char *s_, char ss[][16]) {
int h, hl, hr, j, l, r, c;
l = 0;
while (s[l] != '(') l++;
r = l;
while (s[r] != ')') r++;
hr = l - 1;
while (s[hr] <= ' ') hr--;
hl = hr;
while (hl >= 0 && s[hl] > ' ') hl--;
hl++;
memcpy(s_, s + hl, hr - hl + 1);
s_[hr - h... | 4 |
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, t, w, maxC = 0;
cin >> n >> m;
vector<vector<int>> candyDest(n, vector<int>());
for (int i = 0; i < m; ++i) {
cin >> t >> w;
candyDest[t - 1].push_back(w - 1);
maxC = max(maxC, (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)(1e9);
const long long INF64 = (long long)(1e18);
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
int main() {
int n, l, r;
scanf("%d", &n);
int arr[100005], result;
map<int, int> left;
map<int, int> rig... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000006;
int rnk[MAX], parent[MAX], ans[MAX], arr[MAX];
vector<int> comp[MAX];
priority_queue<int> q[MAX];
int find(int x) {
if (x == parent[x]) return x;
return parent[x] = find(parent[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if... | 4 |
#include <bits/stdc++.h>
const int N = 400005;
struct edge {
int x, y;
} a[N];
int n, m, s, t, p, ds, dt, cnt, ans[N], d[N][2], fa[N];
template <class type>
inline void read(type &k) {
k = 0;
type t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') t = -1;
ch = getchar();
}
w... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
long long int k;
cin >> n >> k;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a.begin(), a.end());
int ans = -1;
long long int l = 0, r = 2e9;
for (int i = 0; i < 60; i++) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
char s[n + 1];
int cnt[26] = {0};
scanf("%s", s);
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a']++;
}
int remove[26] = {0};
for (int i = 0; i < 26; i++) {
if (k <= 0) {
break;
}
if (k >= cn... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 520;
char farm[N][N];
void dfs(int a, int b) {
if (farm[a + 1][b] == 'W' or farm[a - 1][b] == 'W' or farm[a][b + 1] == 'W' or
farm[a][b - 1] == 'W') {
cout << "No";
exit(0);
}
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <=... | 1 |
/*---Don't look at the standing---*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 200004, mod = 1e9 + 7;
char a[N];
ll b[N], dp[505][505];
int j, n;
ll solve(int i, int cnt) {
if (cnt < 0) {
if (i > j)
return 0;
cnt = ... | 4 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
const long N = 1000;
long n;
std::cin >> n;
std::string s;
std::cin >> s;
bool possible(false);
for (long p = 0; p <= N; p++) {
long cur(0), cnt(0);
for (long q = 0; q < s.size(); q++) {
cur += s[q] - '0';
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int n, m;
int i, j;
int ans;
vector<int> v1, v2;
scanf("%d", &t);
int flag = 0;
while (t--) {
v1.clear();
v2.clear();
flag = 0;
scanf("%d%d", &n, &m);
if (n == 0) {
ans = m + 1;
printf("%d\n", ans);
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[200006], b[200006], x[200006], nrel, t;
int main() {
cin >> nrel >> t;
for (int i = 1; i <= nrel; i++) cin >> a[i];
a[nrel + 1] = (long long)3000000000000000000 - 1;
for (int i = 1; i <= nrel; i++) cin >> x[i];
for (int i = 1; i <= nrel; i++)
if (x... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
int n, m;
vector<int> mat[N];
int d[N][N][2];
struct state {
int fir, sec;
bool is;
state(int f = 0, int s = 0, bool i = false) { fir = f, sec = s, is = i; }
} par[N][N][2];
queue<state> q;
vector<int> out[2];
void input() {
cin >> n >> m;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long presum[200001];
int main() {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
sort(a, a + n);
reverse(a, a + n);
presum[0] = 0;
long long ans2 = 0;
for (int i = 1; i < n; i++) {
presum[i] = a[i] + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, e = 0, d = 0;
cin >> n;
long long h[n + 1];
h[0] = 0;
for (long long i = 1; i < n + 1; i++) {
cin >> h[i];
}
for (long long i = 1; i < n + 1; i++) {
e = e + (h[i - 1] - h[i]);
if (e < 0) {
d = d - e;
e = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, arr[N], preSum[N], sufSum[N], preMax[N], sufMax[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &arr[i]), preSum[i] = preSum[i - 1] + arr[i];
for (int i = n; i >= 1; i--) sufSum[i] = sufSum[i + 1] + arr[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int cnt;
bool b[310], good[310];
int a[20], mask[310], d[310][110], kd[310], q[100010];
int aw[100010], ax[100010], ay[100010], az[100010];
int main() {
cin >> cnt;
for (int i = 0; i < 30; i++) b[i] = 0;
int need = 0;
for (int i = 0; i < cnt; i++) {
int foo;
... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, m, n;
scanf("%d%d%d%d", &a, &b, &c, &d);
n = (3 * a) / 10;
if ((a - (a / 250) * c) > n) n = a - (a / 250) * c;
m = (3 * b) / 10;
if ((b - (b / 250) * d) > m) m = b - (b / 250) * d;
if (n > m)
printf("Misha");
else if (m > n)
printf("Vasya");
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int const md = 998244353, R = 810127274, RI = 447056889, P2 = 1 << 23;
inline int pw(int x, int p) {
int an = 1;
while (p) {
if (p & 1) an = (long long)an * x % md;
x = (long long)x * x % md;
p >>= 1;
}
return an;
}
void ntt(vector<int> &v, bool inv = fa... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
class Trie {
public:
Trie *trie[26];
bool win, lose;
void add_word(string &s, int pos) {
if (pos == s.size()) return;
if (trie[s[pos] - 'a'] == nullptr) {
trie[s[pos] - 'a'] = new Trie();
}
trie[s[pos] - 'a']->add_word(s, pos... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main () {
int n; cin >> n;
string S, T;
cin >> S >> T;
vector<int> s(256), t(256);
for (int i = 0; i < n; i++) {
s[S[i]]++;
t[T[i]]++;
}
sort(s.begin(), s.end(), greater<int>());
sort(t.begin()... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x;
while (cin >> x) {
long long i, a, b, arr[10005];
for (i = 1; i <= x; i++) {
arr[i] = i;
}
for (a = 1; a <= x; a++) {
for (b = 1; b <= x; b++) {
if (a % b == 0 && a * b > x && a / b < x) {
cout << a... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 == 0) {
cout << n / 2;
return 0;
}
bool f = 0;
long long k = 0;
for (long long i = 3; i * i <= n; i++) {
if (n % i == 0) {
f = 1;
k = i;
break;
}
}
if (f) {
cout << (1 + (n... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m;
scanf("%d %d\n", &n, &m);
int k = 0;
for (int i = 0; i * i <= n; i++) {
for (int j = 0; j * j <= m; j++) {
if (i * i + j == n && j * j + i == m) {
k++;
}
}
}
printf("%d\n", k);
}
int main() {
solve();
retu... | 1 |
#include <bits/stdc++.h>
int T;
char s[111], a[111];
int len;
bool is_upper(char c) { return 'A' <= c && c <= 'Z'; }
bool is_lower(char c) { return 'a' <= c && c <= 'z'; }
bool is_num(char c) { return '0' <= c && c <= '9'; }
bool chk() {
bool up = false, lo = false, num = false;
for (int i = 0; i < len; i++) {
... | 1 |
/*input
4 3
-1000000000 -1000000000
1000000000 1000000000
-999999999 999999999
999999999 -999999999
*/
#include <bits/stdc++.h>
using namespace std;
int n,k;
pair<long long,long long> a[1000005];
long long check(int x, int y){
long long l=a[y].first-a[x].first,w=1e18;
vector<long long> v;
for(int i=x;i<=y;++i)
v.p... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
bool eq(string a, string b) {
for (int i = 0; i < a.length(); i++) {
if (a[i] == '1' || b[i] == '1') continue;
if (a[i] != b[i]) return false;
}
return true;
}
int main() {
string s;
cin >> s;
int k;
cin >> k;
int n = s.... | 2 |
#include <bits/stdc++.h>
using namespace std;
long double C[2050][2050], sum[2050], ans;
int n, m, d[2050];
double Ans;
inline int Read() {
int x = 0;
char y;
bool z = 0;
do y = getchar(), z |= y == '-';
while (y < '0' || y > '9');
do x = x * 10 + y - '0', y = getchar();
while (y >= '0' && y <= '9');
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long w, b, x;
long long bi[1009];
long long co[1009];
long long dp[1009][10009];
int main() {
scanf("%d%I64d%I64d%I64d", &n, &w, &b, &x);
long long sm = 0;
for (int i = 1; i <= n; i++) scanf("%I64d", bi + i), sm += bi[i];
for (int i = 1; i <= n; i++) sca... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, p = 0;
string x;
int main() {
cin >> t;
while (t--) {
cin >> x;
p += (x.size() + 1) * x.size() / 2;
p += ((int)x[0] - 49) * 10;
cout << p << "\n";
p = 0;
}
}
| 1 |
#include <cstdio>
#include <iostream>
#include <sstream>
#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 <cfloat>
using namespace ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
inline void chmax(int& x, int y) {
if (x < y) x = y;
}
inline void chmin(int& x, int y) {
if (x > y) x = y;
}
inline int LSB(int i) { return (i & -i); }
long long n, m, k, pw[100];
long long Pow(long long a, long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef co... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dist[30][30];
int main() {
int i, j, k;
int n, m;
int u, v;
for (i = 0; i < 30; i++) {
for (j = 0; j < 30; j++) dist[i][j] = 100000000;
}
for (i = 0; i < 30; i++) dist[i][i] = 0;
string s, t;
cin >> s >> t;
if (s.length() != t.length()) {
cout ... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void setmin(int &x, int y) {
if (y < x) x = y;
}
inline void setmax(int &x, int y) {
if (y > x) x = y;
}
inline void setmin(long long &x, long long y) {
if (y < x) x = y;
}
inline void setmax(long long &x, long long y) {
if (y > x) x = y;
}
const int N = 2000... | 5 |
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int> > g, int s, vector<bool> &vis) {
vis[s] = true;
for (int i = 0; i < g[s].size(); i++) {
if (!vis[g[s][i]]) {
dfs(g, g[s][i], vis);
}
}
}
int findComponents(vector<vector<int> > g) {
int t = 0;
vector<bool> vis(g.size(), fa... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long fact(int a) { return a == 0 ? 1ll : a * fact(a - 1); }
long long gcd(long long a, long long b) { return a == b ? a : gcd(b % a, a); }
long long C(int n, int k) { return k == 0 ? 1ll : C(n - 1, k - 1) * n / k; }
long long toInt(string s) {
istringstream iss(s);
... | 1 |
#include<bits/stdc++.h>
using namespace std;
long long ans = INT64_MAX;
long long dif(long long a, long long b, long long c) {
return max(a, max(b, c))-min(a, min(b, c));
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
long long H, W;
cin >> H >> W;
long long A, B, C;
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, d, ct = 0;
string str;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> str >> d;
if (str[0] == '+') {
x += d;
} else {
if (x - d >= 0) {
x -= d;
} else {
ct++;
}
}
}
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &varVal, const Args &...args) {
string varName;
*iss >> varName;
if (varName.back() == ',') varName.back() = ' ';
cout << varName << " = " << varVal << "; ",... | 5 |
#include <bits/stdc++.h>
char A[50][50];
int main() {
int n;
std::cin >> n;
int fr_i = n + 1;
int to_i = -1;
int fr_j = n + 1;
int to_j = -1;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
std::cin >> A[i][j];
if (A[i][j] == '4') {
fr_i = std::min(fr_i, i);
to_... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[33], b[33], k[33], p[33], u, r, n;
long long an = -1000000000000000000ll;
set<pair<long long, int> > H;
void dfs(int x, int ha[], long long yo) {
if (H.count(make_pair(yo, x))) return;
H.insert(make_pair(yo, x));
int i;
if (!(x & 1)) {
long long tmp = 0;
... | 4 |
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int n, q;
cin >> n;
vector<int> s(n);
rep(i,n) cin >> s[i];
int ct = 0;
cin >> q;
rep(i,q) {
int left = 0;
int right = n-1;
int x;
cin >> x;
if (*lower_bound... | 0 |
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); i++)
int main() {
int T; cin >> T >> ws;
while(T--) {
string buf;
getline(cin, buf);
// cout << buf << endl;
// i == buf.size()ÆÈ鱯à éB
// eof <=> i == buf.size... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int setBit(int mask, int pos) { return (mask | (1 << pos)); }
inline int resetBit(int mask, int pos) { return (mask & ~(1 << pos)); }
inline bool checkBit(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int l, r;
bitset<300000005> mark;
void sieve(int lim) {... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
int sq = sqrt(x) + 1;
vector<int> v;
for (int i = 1; i < sq; i++) {
if (x % i == 0) {
if ((i <= n) && (x / i <= n)) v.push_back(i);
if (x % i == 0 && i * i != x) {
if ((i <= n) && (x / i <= n)) v.push_b... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> ll;
typedef vector<long long> vl;
typedef vector<ll> vll;
typedef vector<vl> vvl;
template <typename T>
ostream &operator<<(ostream &o, vector<T> v) {
if (v.size() > 0) o << v[0];
for (unsigned i = 1; i < v.size(); i++) o << " " << v[i... | 3 |
#include <iostream>
using namespace std;
double epsilon = 0.000001;
double count(double c, double m, double p, double v, int depth){
double ret = p*depth;
bool addToC = 1;
bool addToM = 1;
if(c<epsilon){
addToC = 0;
}
if(m<epsilon){
addToM = 0;
}
if(c>=v){
ret ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
long long n, t;
vector<long long> a;
vector<long long> x;
vector<long long> ret;
scanf("%lld %lld", &n, &t);
for (long long i = 0; i < n; i++) {
long long tmp;
scanf("%lld", &tmp);
a.push_back(tmp);
}
for ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 200005;
int cth[MAX];
int ctv[MAX];
int main() {
int a, b, n;
scanf("%d %d %d", &a, &b, &n);
set<int> h;
set<int> maxh;
set<int> maxv;
set<int> v;
h.insert(0);
h.insert(b);
v.insert(0);
v.insert(a);
maxh.inse... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int temp;
string s;
cin >> s;
for (int i = 0; i < s.length(); i = i + 2) {
for (int j = i + 2; j < s.length(); j = j + 2) {
if (s[i] > s[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
cout << s;
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
int dp[20][100005];
void make(vector<int> &a) {
int n = int((a).size());
for (int i = 0; i < int(n); i++) dp[0][i] = a[i];
for (int j = 1; (1 << j) <= n; j++)
for (int i = 0; i + (1 << j) - 1 < n; i++) {
dp[j][i] = dp[j - 1][i] | dp[j - 1][i + (1 << (j - 1))... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, prt[100001][2] = {}, anc[100001], disc[100001] = {}, idx = 1;
vector<vector<pair<int, int> > > adj;
vector<int> ans;
stack<pair<pair<int, int>, int> > sk;
inline void stkout() {
stack<pair<pair<int, int>, int> > tp = sk;
cout << "Stack Size : " << tp.size() <<... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:512000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 ... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.