solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
//#include <complex>
//#include <deque>
#include <valarray>
// stream
//#include <istream>
//#include <sstream>
//... | 0 |
#include <bits/stdc++.h>
using namespace std;
void test_case() {
long long n, m;
cin >> n >> m;
long long mn = m, mx = m, time = 0, flag = 0;
long long t, l, h;
for (int i = 0; i < n; i++) {
cin >> t >> l >> h;
long long d = t - time;
mn -= d, mx += d;
if (mx < l || mn > h) {
flag = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int k[n];
for (int i = 0; i < n; i++) {
scanf("%d", &k[i]);
}
int mi = 1e9;
for (int i = 0; i < n; i++) {
int t = 15 * k[i];
for (int j = 0, a; j < k[i]; j++) {
scanf("%d", &a);
t += a * 5;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, digit = 0, tmp, nine = 0, one = 0, i, ones = 1, res = 0;
cin >> n;
tmp = n;
while (tmp) {
digit++;
tmp = tmp / 10;
}
if (digit - 1 > 0) {
for (long long int i = 1; i <= digit - 1; i++) {
nine = nine + 9;
res ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int data[9][9] = {{0, 0, 1, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 1, 0, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 0, 1}, {0, 0, 0, 0, 0, 0, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 0, 0, 1},... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, cycle1, cycle2, cur, H[(int)(2e5 + 10)], p[(int)(2e5 + 10)];
bool cift;
vector<int> ans[2];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
for (int i = 1; i <= n; i++) {
if (p[i] == i) cycle1 = i;
if (p[p[i]] == i) cycle2 = i;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long g, long long c1, long long c2, long long ones,
long long zeros) {
long long p = (ones + zeros) / g;
long long r = (ones + zeros) % g;
long long sum = 0;
for (long long i = 0; i < g; i++) {
if (i < r)
sum += c1 + c2 * p * p... | 1 |
#include <bits/stdc++.h>
using namespace std;
class DNashMatrix {
vector<vector<char> > grid;
vector<vector<pair<int, int> > > graph;
int n;
bool isIn(int r, int c) { return (r >= 0 && c >= 0 && r < n && c < n); }
bool BFS(pair<int, int> src) {
int X = src.first;
int Y = src.second;
if (grid[X][Y]... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s){
if(s.length()==3) reverse(s.begin(),s.end());
cout<<s<<endl;
}
} | 0 |
#include <iostream>
#include <string>
using namespace std;
int main() {
string a, b;
int n, t = 0, h = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
a == b ? t++, h++ : (a > b ? t += 3 : h += 3);
}
cout << t << " " << h << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, eq;
map<pair<int, int>, int> mp;
int main() {
cin >> c >> d >> a >> b;
if (a == b) eq = 1;
int now = 1;
while (a != 0 || b != 0) {
mp[{a, b}] = now;
if (a > 0 && b > 0)
a--, b--;
else if (a > 0)
a--;
else
b--;
no... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[101], d = 0, i, m, z, t = 0;
int main() {
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
d = a[i] - a[i - 1];
m = a[i];
break;
}
}
for (i = n - 2; i >= 0; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename... Args>
inline void unused_args(Args &&...args) {
(void)(sizeof...(args));
}
int main() {
std::ios_base::sync_with_stdio(false);
std::streamsize ss = cout.precision();
unused_args(ss);
long long n, k;
cin >> n >> k;
long long ans = k % n ? ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1007];
bool check() {
for (int i = 1; i < n; ++i)
if (a[i] && a[i + 1]) return 0;
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%1d", &a[i]);
if (!check())
printf("No");
else {
int ok = 1;
for (int i = 1; ... | 1 |
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl
using namespace std;
const int N = 1000006;
ll t, n, m, q, a, b, x, y, k... | 1 |
#include <bits/stdc++.h>
using namespace std;
int arr[101];
bool inside[101];
vector<int> factors[101];
vector<pair<int, int> > edgesIndexes[101];
int pairs[100000], dist[100000];
vector<int> G[100000];
vector<int> L1, L2;
void factorize(int n, int index) {
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
... | 3 |
#include <iostream>
using namespace std;
int main(){
int a,sum=100000,b;
cin >>a;
for(int i=0;i<a;i++){
b=sum/20;
if(b%1000==0)sum+=b;
else sum+=(b/1000+1)*1000;
}
cout <<sum<<endl;
return 0;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 300010;
struct CHT {
vector<ll> M, B;
void init() {
M.clear();
B.clear();
}
bool bad(int l1, int l2, int l3) {
return (M[l1] - M[l2]) * (B[l3] - B[l1]) <= (M[l1] - M[l3]) * (B[l2] - B[l1]);
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, t = -1, o;
int main() {
cin >> n >> m >> h;
n--;
h--;
for (int i = 0; i < m; i++) {
int s;
cin >> s;
t += s;
if (i != h) o += s;
}
if (t < n)
cout << -1.0 << endl;
else if (o < n)
cout << 1.0 << endl;
else {
double p ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int b[105];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
for (int i = 0; i < n; i++) {
scanf("%d", b + i);
}
int ascore = 0, bscore = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1 && b[... | 1 |
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cout<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,... | 0 |
#include <iostream>
#include <cassert>
using namespace std;
typedef long long ll;
int N,cnt[110] = {};
ll p[110],q[110],r[110],b[110],dp[110] = {};
ll gcd(ll n,ll m){
assert(m!=0);
if(n%m==0) return m;
else return gcd(m,n%m);
}
void dfs(int n){
if(n==0){
dp[0] = 1;
}else{
dfs(r[n])... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int INF = 1e9 + 5;
const long long mod = 1e9 + 7;
const double pi = 3.1415926536;
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ios_base::sync_with_stdio(0... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pci = pair<char, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
const ll infll = 1e18 + 3;
const int ma... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct rectangle {
long long c1, r1, c2, r2;
pair<long long, long long> get_sp_impose() {
long long sum = (c2 - c1 + 1) * (r2 - r1 + 1);
long long fc_tmp = sum / 2;
long long sum_white, sum_black;
if ((c1 + r1) % 2 == 0) {
sum_black = fc_tmp;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn], b[maxn];
vector<pair<int, int>> G[maxn];
bool v[maxn], use[maxn];
struct data {
int a, b, c;
};
vector<data> ans;
void dfs(int now, int fa, int edge) {
v[now] = true;
int nxt = -1, cid = -1;
for (auto u : G[now])
if (u.fir... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int other = -1, X;
int pre[200010];
int cnt[200010];
long long C, N;
bool can() {
int cur = C;
int last = C;
while (cur) {
int to = pre[last];
if (other != -1 && other <= cur && other > to) {
cur -= other;
other = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (1 << 31) - 1;
int main() {
int n;
scanf("%d", &n);
if (n == 5)
cout << "1";
else
printf("%d", (n % 3) + 1);
return 0;
}
| 4 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX_N 1120
#define MAX_K 15
int main(){
bool p[MAX_N+1];
memset(p, true, sizeof(p));
p[0] = p[1] = false;
for(int i = 2 ; i*i <= MAX_N ; i++){
if(p[i]){
for(int j = i*i ; j <=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f, x, y, z;
cin >> a >> b >> c >> d >> e >> f;
x = a + b;
y = b + c;
z = a + c;
if (x + c == d + e + f || x + d == c + e + f || x + e == c + d + f ||
x + f == c + d + e || y + d == a + e + f || y + e == a + d + f ||
y ... | 1 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int h, w, leaves;
vector<char> path;
char mapData[10][10];
bool visited[10][10];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};
const string str = "URDL";
bool dfs(int y, int x, int d){
if(leaves == 0){
path... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxt = int(1e7) + 5;
int n, m, k, mark[maxt];
vector<int> f;
vector<pair<int, int>> s;
bool check(int x) {
for (int i = 0; i < x; i++) mark[s[i].first]++;
int drinks = 0;
bool done = 1;
for (int i = 0; i < maxt; i++) {
drinks += mark[i];
if (mark[i... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int64_t x,y,z;
cin >> x >> y >> z;
cout << z <<" "<<x<<" "<<y;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void max_swap(T& a, const T& b) {
a = max(a, b);
}
template <class T>
void min_swap(T& a, const T& b) {
a = min(a, b);
}
template <class T>
void uniq(vector<T>& c) {
sort(c.begin(), c.end());
c.erase(unique(c.begin(), c.end()), c.end());
}
templat... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dp[100005][205];
int n, m, k, b[100005], e[100005], to[100005], pr[100005];
vector<int> fin[100005], st[100005];
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
int m;
int f;
cin >> n >> m >> f;
for (int i = 0; i < f; i++) {
ci... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 10000005;
const int di[] = {-1, 0, 1, 0, 1, -1, 1, -1};
const int dj[] = {0, 1, 0, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false), cin.tie(0);
string s;
cin >> s;
vector<int> cnt;
vector<char> ltr;
for (int i = 0; i < s.length(); i++... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
char s[4][N];
int p[4][N], l[4], cut[4][4], ans = INT_MAX;
void get_next(int now) {
int j = 0;
l[now] = strlen(s[now] + 1);
for (int i = 2; i <= l[now]; i++) {
while (j && s[now][i] != s[now][j + 1]) j = p[now][i];
if (s[now][i] == s[now]... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T inline sqr(T x) {
return x * x;
}
template <class T>
inline void relaxMin(T &a, T b) {
a = min(a, b);
}
template <class T>
inline void relaxMax(T &a, T b) {
a = max(a, b);
}
string str(int i) {
char s[100];
sprintf(s, "%d", i);
return string... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class TF, class TC>
struct CostFlow {
static const int MAXV = 10000;
static constexpr TC INF = 1e9;
struct Edge {
int v, r;
TF f;
TC c;
Edge(int _v, int _r, TF _f, TC _c) : v(_v), r(_r), f(_f), c(_c) {}
};
int n, s, t, pre[MAXV], pre_E[MA... | 5 |
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
double a,b;
cin>>a>>b;
a=a*b;
a=a/3.3057851;
cout<<fixed<<setprecision(6)<<a<<endl;
} | 0 |
#include<iostream>
#include<vector>
#include<cmath>
#include<complex>
#define MAX 21
#define INF 10000
#define EPS 1.0e-10
using namespace std;
typedef double elem;
typedef complex<elem> point;
double dist(const point &a, const point &b){return std::abs(b-a);}
bool vis[MAX];
bool bt(const vector<point> &v, double walk,... | 0 |
#include <iostream>
using namespace std;
int main()
{
int K, X;
cin >> K >> X;
cout << (X <= 500*K ? "Yes" : "No") << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
vector<int> g[maxn + 5];
int dep[maxn + 5], mx[maxn + 5], son[maxn + 5];
int n, root;
priority_queue<pair<int, int> > q;
void dfs(int k, int fa) {
dep[k] = dep[fa] + 1;
son[k] = dep[k];
mx[k] = 0;
for (auto u : g[k]) {
if (u == fa) continue... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve(int n, long long p, long long q, long long r, vector<long long> a) {
vector<long long> ll(n), lr(n), sl(n), sr(n);
ll[0] = a[0];
sl[0] = a[0];
for (int i = 1; i < n; i++) {
ll[i] = max(ll[i - 1], a[i]);
sl[i] = min(sl[i - 1], a[i]);
}
lr[n - 1... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
const int M = 1000000007;
int n, k;
string s;
int dp[1007][1007][2];
int get(int it, int d, bool zero, bool complete) {
if (d > k) d = 1001;
if (it == 0) return complete;
if (zero && dp[it][d][complete] != -1) return dp[it][d... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int a[200010], b[200010], vis[200010];
vector<long long int> G[200010], ans[2];
long long int Ans;
void dfs(long long int x) {
vis[x] = 1;
for (long long int to : G[x]) {
if (!vis[to]) {
dfs(to);
}
}
Ans += a[x];
if (b[x] != -1 and a[x] > 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
string a, b, c;
cin >> t;
while (t--) {
bool f = 0;
cin >> a >> b >> c;
for (auto i = 0; i < a.size(); ++i) {
if (!(c[i] == a[i] || c[i] == b[i])) {
f = 1;... | 1 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
while (1) {
if (a == 0) {
return b;
}
if (b == 0) {
return a;
}
if (a >= b) {
a %= b;
} else {
b %= a;
}
}
}
long long search(long long left, long long right, int n, long long b) {
int l, r, m;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long k, n, s, p;
int main() {
ios_base::sync_with_stdio(false);
cin >> k >> n >> s >> p;
int t = ceil(k * n * 1.0 / s);
int v = ceil(t * 1.0 / k);
cout << (long long)ceil(v * k * 1.0 / p);
return 0;
}
| 1 |
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back
using namespace std;
typedef pair<double, string> P;
bool solve(){
int n;
cin>>n;
if(n==0)return false;
vec... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int N, M, K, Q, R, S[105], EXP[105], choose[105][105],
dp[105][105 * 105], tmp;
long long int exponentiate(long long int v, long long int p) {
if (p == 1) return v;
if (p & 1ll) return (v * exponentiate(v, p - 1ll)) % 1000000007;
return exponentiate((v *... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long x[30];
for (long long i = 0; i < 26; i++) {
cin >> x[i];
}
string s;
cin >> s;
long long n = s.size();
long long pre[n + 1];
pre[0] = 0;
for (long long i = 1; i <= n; i++) {
pre[i] = pre[i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N, P[2005], Ans;
vector<int> AdjList[2005];
int dfs(int u) {
int height = 0;
for (auto v : AdjList[u]) height = max(height, dfs(v));
return height + 1;
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", &P[i]);
AdjList[P[i]].pus... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const int MAXN = 100010;
int n, q;
int A[MAXN], B[MAXN];
int L[MAXN], R[MAXN];
set<pair<int, int> > st;
set<pair<int, int> >::iterator it;
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; ++i) {
scan... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string co[107];
pair<int, int> tab[107];
vector<int> lew[107];
vector<int> pra[107];
long long dp[107][107];
int czy;
int u;
int main() {
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> tab[i].first >> co[i] >> tab[i].second;
if (tab[i].first > ta... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 5e5 + 5;
const int mod = 1e9 + 7;
const int INF = 1e9;
void solve() {
int n;
cin >> n;
vector<array<int, 2>> ans;
int xorsum[n];
int degree[n];
queue<int> Q;
int used = 0;
for (int i = 0; i < n; i++) {
cin >> degree[i] >> xorsum[i];
i... | 1 |
//#pragma comment(linker, "/STACK:60777216")
#include <cassert>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<complex>
#include<vector>
#include<cstring>
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<string>
#include<cstdlib>
#include<memory.h>
#include<ctime>
#include<bit... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct fff {
int x, y;
} mark[1000010];
int cmpx(fff a, fff b) { return a.x < b.x; }
int cmpy(fff a, fff b) { return a.y < b.y; }
int n, m;
char graph[1010][1010];
int x[1010];
int y[1010];
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", g... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int m, n;
char s[maxn];
int main() {
scanf("%d%s", &n, s + 1);
for (register int i = 1; i <= n; ++i) {
m += (s[i] == '(' ? 1 : -1);
if (m < -1) {
puts("No");
return 0;
}
}
puts(m ? "No" : "Yes");
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7, N = 2e5 + 10;
const int M = 400;
int st[N];
int seg[M][M];
int strt[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<array<int, 2>> a(n);
for (int i = 0, x, y; i < n; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int memo[1002][1002];
string s;
int Calc(int from, int tarpos) {
if (memo[from][tarpos] != -1) {
return memo[from][tarpos];
}
int i, tb, j;
int ret = 0, cur;
int afr, ato;
for (i = from + tarpos + 1; i < s.size(); i++) {
tb = i - tarpos + i - 1 - from;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
ll h, w, k;
cin >> h >> w >> k;
vector<string> S(h);
for (auto &s : S)
cin >> s;
vector<vector<ll>> ANS(h, vector<ll>(w));
{
int now = 0;
for (int i = 0; i < h; i++)
{
for (int j = 0; j < w; j++)
{
if(S[i][j]=='#... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int p = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
cin >> t;
while (t--) {
long long int p, q;
cin >> p >> q;
if (p < q) {
cout << p << '\n';
;
continue;
}
if (p >= q && p ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long c[100005];
map<long long, long long> mama;
int main() {
long long n, i, j, k, ans = 0;
long long sum = 0, x;
scanf("%lld%lld", &n, &k);
for (i = 0; i < n; i++) {
scanf("%lld", &c[i]);
sum += c[i];
}
ans += c[0] * c[n - 1];
for (i = 0; i < n -... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') f = (c == '-') ? -1 : 1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
int n;
int a[200010];
int cnt[200010], t = 0;
set<int> p,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int hang[100001];
int lie[100001];
int geshuhang;
int geshulie;
long long ans;
int main() {
while (scanf("%d %d", &n, &m) == 2) {
int x;
int y;
ans = (long long)n * n;
geshuhang = 0;
geshulie = 0;
memset(hang, 0, sizeof(hang));
me... | 2 |
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int mod=1e9+7;
const int maxn=1000;
int n,m,k,ans=1,tot=1,tail,cnt,Time;
int pre[maxn*2+8],now[maxn+8],son[maxn*2+8];
int fac[maxn*2+8],fact[maxn*2+8],st[maxn+8];
int dfn[maxn+8],low[maxn+8];
bool vis[ma... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 50;
const long long mod = 998244353;
const long long base = 1e18;
long long a[maxn];
long long b[maxn];
long long pos[maxn];
bool dd[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("t.inp", "r")) ... | 2 |
#include<iostream>
#include<cfloat>
#include<cassert>
#include<cmath>
#include<vector>
using namespace std;
#define EPS (1e-8)
#define equals(a, b) (fabs((a) - (b)) < EPS )
#define dle(a, b) (equals(a, b) || a < b )
static const double PI = acos(-1);
class Point{
public:
double x, y;
Point ( double... | 0 |
#include<bits/stdc++.h>
using namespace std;
struct var{
long long to,nxt;
}edge[201001];
long long u,v,c[101001],x1,x2,n,m,head[101001],cnt;
bool flag;
void add(long long u,long long v)
{
cnt++;
edge[cnt].to=v;
edge[cnt].nxt=head[u];
head[u]=cnt;
}
void dfs(long long o,long long cc)
{
c[o]=cc;
if(c[o]==1)x1++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
priority_queue<pair<l... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18 + 5;
const int mod = 1e9 + 7;
const int logN = 16 + 1;
const int inf = 1e9 + 0;
const int N = 1e5 + 5;
int n, q, x, l, r;
map<int, int> F, h;
void update(int x, int y) {
for (; x <= n; x += x & -x) F[x] += y;
}
int query(int x) {
int sum = 0;... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
Finish_read = 0;
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
if (ch == EOF) return;
ch = getchar();
}
while (isdigit(ch))... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 80;
int dp[maxn][maxn][maxn][3];
char str[maxn];
int n;
int arr[maxn], cnt[3];
int bef[3][maxn][3];
int main() {
scanf("%d%s", &n, str);
for (int i = 0; i < n; i++) {
if (str[i] == 'V')
arr[i] = 0;
else if (str[i] == 'K')
arr[i] = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:400000000")
double S, a, b, c;
double f(double x, double y) {
if (x == 0)
return 0;
else
return exp(x * y);
}
int main() {
cin >> S >> a >> b >> c;
if (a + b + c < 5e-12)
cout << "0 0 0";
else {
double d = a + b + c;... | 2 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<c... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, k, count = 0, temp = 0;
cin >> n >> k;
while (n != 0) {
if (n % k == 0) {
n = n / k;
count++;
} else {
temp = n % k;
n = n - n % k;
count += te... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
if (y == 0)
return 1;
else if (y % 2 == 0)
return power(x, y / 2) * power(x, y / 2);
else
return x * power(x, y / 2) * power(x, y / 2);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NUL... | 5 |
#include <bits/stdc++.h>
#define N 5005
#define INF 10000000000000LL
using namespace std;
int n,A,B,p[N],pos[N],cnt[N][N];
long long f[N][N];
int main(){
scanf("%d%d%d",&n,&A,&B);
for(int i=1;i<=n;++i){
scanf("%d",&p[i]);
pos[p[i]]=i;
}
for(int i=n;i;--i)
for(int j=1;j<=n;++j)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long double x;
cin >> x;
long double DELTA__ = (long long)1e18;
long double o, p;
for (long double a = 1; a <= 10; a += 1)
for (long double h = 1; h <= 10; h += 1)
if (fabs(a * a * h * h / (a *... | 5 |
#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string fst, snd, message;
std::cin >> fst >> snd >> message;
std::map<char, char> transform;
for (size_t i = 0; i < 26; ++i) {
transform[fst[i]] = snd[i];
transform[fst[i] + 'A' - 'a'] = snd[i] +... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long N,ans=0;
cin >> N;
for(long long int i = 1;i * i <= N; ++i){
if(N%i==0){
if(N/i>i+1){
ans += N/i-1;
}
}
}
cout << ans << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = 0x7fffffff;
}
int q = -1;
for (int i = 0; i < n; i++) {
if (a[i] == 0) {
q = i;
}
if (q != -1) b[i] = i - q;
}
q = -1;
for (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
;
int tc;
cin >> tc;
while (tc--) {
int a, b, x, y;
cin >> a >> b >> x >> y;
x++;
y++;
long long l1 = (x - 1) * b;
long long l2 = (a - x) * b;
long long l3 = (y... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 4223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
int a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1005];
int msk[1005];
int main() {
int n;
ignore = scanf("%d", &n);
for (int i = 0; i < n; i++) {
char buf[5];
ignore = scanf(" %d %s", a + i, buf);
int m = strlen(buf);
for (int j = 0; j < m; j++) {
msk[i] |= (1 << (buf[j] - 'A'));
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int v[2][1000000 + 10];
void solve(int n, int p) {
if (n == 0) {
v[p][0] = 0;
return;
}
if (!(n & (n + 1))) {
for (int i = 0; i <= n; ++i) {
v[p][i] = n - i;
}
} else {
int two = 1;
while (two * 2 < n + 1) two *= 2;
solve(n -... | 5 |
#include <bits/stdc++.h>
using namespace std;
int message[100010];
int key[100010];
int main() {
int n, m, c;
while (cin >> n >> m >> c) {
int i, j;
for (i = 0; i < n; i++) cin >> message[i];
for (i = 0; i < m; i++) cin >> key[i];
for (i = 0; i <= n - m; i++) {
int k = 0;
for (j = i; j <... | 4 |
#include<bits/stdc++.h>
using namespace std;
long long int x[500010];
int mod = 1e9 + 7;
int cnt[61];
long long int ok[61];
long long int okn[61];
void solve() {
int n;
cin>>n;
memset(cnt,0,sizeof cnt);
memset(ok,0,sizeof ok);
memset(okn,0,sizeof okn);
for(int i = 0; i < n; i++) {
cin>>x[i];
for(int j = 59; j... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<int> m;
unsigned long long s = 0;
set<int>::iterator it;
int n, x;
cin >> n;
while (n--) {
cin >> x;
if (m.find(x) == m.end())
m.insert(x);
else
while (m.find(x) != m.end()) x--;
if (x != 0) m.insert(x);
}
for (it... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v(1505);
int n, m, l, r, k, s;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
for (int i = 1; i <= n - 1; i++) {
for (int j = i + 1; j <= n; j++) {
if (v[j] < v[i]) k++;
}
}
cin >> m;
k %= 2;
while (m--) {
cin >>... | 4 |
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
long long n;
long long f[400];
int main()
{
scanf("%d",&n);
f[0]=2;
for(int i=0;i<=n;i++)
f[i]=f[i-1]*2+2;
cout<<f[n]<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char ch[8];
int v[1001];
int n;
void umplere(int j, int p) {
int i;
if (p == 1) {
for (i = j - 1; i >= 1; i--) v[i]++;
} else {
for (i = j + 1; i <= n; i++) v[i]++;
}
}
int main() {
int i, m, p, j, maxim1 = 0, x;
cin >> n >> m;
for (i = 1; i <= m; i++)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cancollect[5000];
int frombefore[5000];
for (int i = 0; i < 5000; i++) {
cancollect[i] = 0;
frombefore[i] = 0;
}
int n, v;
cin >> n >> v;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
cancollect[a] += b;
}
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int spf[5000001], cum_sum[5000001] = {0};
vector<long long int> factors;
void store() {
for (long long int i = 1; i <= 5000000; i++) i % 2 ? spf[i] = i : spf[i] = 2;
for (long long int i = 3; i * i <= 5000000; i += 2) {
if (spf[i] == i) {
for (long l... | 4 |
#include <bits/stdc++.h>
using namespace std;
int get(int n, int m, int a, int b) {
int line1 = (a - 1) / m, r1 = m - (a - 1) % m;
int line2 = (b - 1) / m, r2 = (b - 1) % m + 1;
if (line1 == line2) {
return 1;
}
if (r1 == m && r2 == m) {
return 1;
}
if (line1 + 1 == line2) {
return 2;
}
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1510;
complex<long long> cmpt;
bool pcomp(complex<long long> a, complex<long long> b) {
a -= cmpt;
b -= cmpt;
return a.real() * b.imag() > a.imag() * b.real();
}
bool comp(const pair<complex<long long>, int> &pa,
const pair<complex<long long... | 3 |
#include<bits/stdc++.h>
using namespace std;
#define CO const
#define IN inline
typedef long long int64;
template<class T> IN T read(){
T x=0,w=1;char c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*w;
}
template<class T> IN T read(T&x){
return x=rea... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int gcd(int m, int n) {
if (m < n) {
int tmp = m;
m = n;
n = tmp;
}
if (n == 0)
return m;
else
return gcd(n, m % n);
}
int n, g;
long long a[100005];
int ma... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int N = 312345;
int seen[N], second[N], low[N], ok[N], p[N], tempo;
vector<pair<int, int> > adj[N];
void dfs(... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.