solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
namespace patch {
template <typename T>
std::string to_string(const T& n) {
std::ostringstream stm;
stm << n;
return stm.str();
}
} // namespace patch
struct Point {
double x, y;
};
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
bool... | 5 |
#include <iostream>
#include<iomanip>
#include<math.h>
using namespace std;
int main() {
while(1){
int n;
cin>>n;
if(n==0)break;
int s[n];
double sum=0;
for(int i=0;i<n;i++){
cin>>s[i];
sum+=s[i];
}
double a=0;
sum/=n;
for(int i=0;i<n;i++)a+=pow(s[i]-sum,2)/n;
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<int, vector<int>, greater<int> > pqg;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int> > data[26];
vector<string> d;
string temp;
for (int i = 0; i < n; ++i) {
cin >> temp;
d.... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
long long REM(long long a) {
a %= MOD;
if (a < 0) a += MOD;
return a;
}
long long ADD(long long a, long long b) { return REM(REM(a) + REM(b)); }
long long SUB(long long a, long long b) { return REM(REM(a) - REM(b)); }
long long MUL(l... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
scanf("%lld", &N);
long long ans = 1;
while (2 * ans - 1 < N) {
ans++;
}
printf("%lld\n", ans);
long long cnt = 0;
for (long long i = 1; i <= ans; i++) {
cout << "1"
<< " " << i << endl;
cnt++;
if (cnt == N)... | 2 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int dp[61][61][3001];
int main(){
int N,K;
cin >> N >> K;
vector<int> A(N+1),R(K+1),B(K+1);
int sumA = 0,sumR = 0,sumB = 0;
for(int i=1;i<=N;i++){
cin >> A[i];
sumA += A[i];
}
for(int i=1;i<=K;i... | 0 |
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typede... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const long long INF = 1e18 + 7;
long long a[maxn], b[maxn], t[maxn], s[maxn], k[maxn];
struct Tree {
long long sum, change;
};
Tree tree[maxn << 2];
void push_up(int o, int l, int r) {
tree[o].sum = tree[(o << 1)].sum + tree[(o << 1 | 1)].sum;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[3005];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
a[x] = 1;
}
for (int i = 1; i <= 3000; i++)
if (a[i] == 0) {
printf("%d\n", i);
return 0;
}
printf("3001\n");
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long big = 1000000007ll;
const long long big2 = 1000000009ll;
long long n, m, k, q, w, h, T;
const long long maxl = 12;
bool exist[201][maxl][(1 << maxl)] = {0};
vector<string> fir;
vector<string> las;
long long now = 0;
long long con... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[200001][22];
int p[200001];
int d[200001];
int lca(int u, int v) {
if (d[u] < d[v]) swap(u, v);
int k = d[u] - d[v];
while (k > 0) {
int t = log2(k);
k -= (1 << t);
u = a[u][t];
}
if (u == v) return v;
for (int i = 20; i >= 0; i--) {
if (a[... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,Q;cin>>N>>Q;
string S;cin>>S;
vector<int>C(N+1,0);
for(int i=1;i<N;i++)C[i+1]=C[i]+(S.substr(i-1,2)=="AC");
for(int i=0;i<Q;i++){
int l,r;cin>>l>>r;
cout<<C[r]-C[l]<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int f, b, sf[2 * N], sb[2 * N], s[N * 2], d[2 * N];
map<int, int> st;
int main() {
int T, n;
cin >> n;
int k = 1, t = 0;
memset(sf, 0, sizeof(sf));
memset(sb, 0, sizeof(sb));
memset(d, 0, sizeof(d));
for (int i = 0; i < n; i++) {
scan... | 2 |
#include <iostream>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;
struct Node {
int key;
Node *right, *left, *parent;
};
Node *root, *NIL;
void insert(int k) {
Node *x = root;
Node *y = NIL;
Node *z;
z = (Node*)malloc(sizeof(Node));
z->key = k;
z->left = NIL;
z->rig... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
char str[305][305];
int a[305];
int vis[305];
int tmp[305];
void dfs(int x) {
if (vis[x]) return;
vis[x] = 1;
for (int i = 0; i < n; i++)
if (str[x][i] == '1') dfs(i);
}
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) scanf("... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
if (fabs(d) < eps) return 0;
return d > eps ? 1 : -1;
}
struct treap {
struct tnode {
tnode *l, *r;
int x, size, k;
const int h;
tnode(int a) : l(NULL), r(NULL), x(a), k(1), ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> a;
a.reserve(n);
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s == "sum") {
long long sum = 0;
int sz = a.size();
for (int j = 2; j < sz; j += 5) sum += a[j];
printf("%I6... | 4 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
inline int read() {
int x = 0, y = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') y = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return y ? ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long n, k;
long long a[maxn];
map<int, int> mp;
bool check(long long x) {
while (x) {
long long base = 1;
long long cnt = 0;
while (x >= base) {
base *= k;
++cnt;
}
base /= k;
--cnt;
++mp[cnt];
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
using i8 = int8_t;using i16 = int16_t;using i32 = int32_t;using i64 = int64_t;using u8 = uint8_t;using u16 = uint16_t;using u32 = uint32_t;using u64 = uint64_t;using f32 = float;using f64 = double;
using vi32 = vector<i32>;using vi64 = vector<i64>;using vvi32 = vector<vi... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int n;
struct Node {
int a, l;
bool operator<(const Node& node) const {
if (a == node.a) {
return l < node.l;
}
return a < node.a;
}
} node[MAXN];
set<pair<int, int>, greater<pair<int, int>>> segs[MAXN][MAXN];
set<int> posS... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1000000000 + 7;
const int MOD = (int)998244353;
const int INF = (int)1e18;
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
return a.second - a.first < b.second - b.first;
}
long long bit_ct1(long long x) {
long long ct = 0;
while (x >... | 3 |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define R return
#define B break
#define C continue
#define sf scanf
#define pf printf
#define pb push_back
#define F first
#define S second
using namespace std;
const ll Mod=1e9+7;
ll poww(ll a,ll b,ll mod){
ll res=1;if(b<0)b=(b%(mod-1)+mod-1)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s, l = 0, a[100010];
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
while (k > l) {
l++;
k -= l;
}
if (k)
s = k - 1;
else
s = l - 1;
cout << a[s] << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 25;
vector<pair<int, int> > yaz;
vector<int> tas;
int ar[MAXN];
void f(int kim, int yer, int git, bool x) {
if (kim == tas.size()) return;
if (tas[kim] == 1) x = 1;
int tmp = 1 + 2 + 3 - git - yer;
if (x) {
f(kim + 1, yer, tmp, 1);
for (int ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int b = 0, c;
cin >> c;
string a;
cin >> a;
for (int i = 0; i < c; i++)
if (a[i] == a[i - 1]) b++;
cout << b;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int in[110];
bool u[110];
int l[110], lc;
int main() {
int k, n, i;
scanf("%d%d", &k, &n);
int mi = 1000000000, ma = -1;
for (i = 1; i <= k; i++) scanf("%d", &in[i]);
int q;
int cc = k / n;
scanf("%d", &q);
while (q--) {
int s = 0;
for (i = 0; i < cc... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
using namespace std;
int t, n, k, a[200005], b[200005], pos[200005];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> t;
while (t--) {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, vA, m, A[100010];
inline void Read(int &digit) {
digit = 0;
char c;
for (c = getchar(); c < '0' || c > '9'; c = getchar())
;
for (; c >= '0' && c <= '9'; digit = digit * 10 + c - '0', c = getchar())
;
}
void read() {
for (int i = 1; i <= n; ++i) Rea... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[3005], i, j, q;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++)
for (j = i + 1; j <= n; j++)
if (a[i] > a[j]) q++;
if (q % 2 == 0)
cout << q * 2;
else
cout << q * 2 - 1;
cout << ".000... | 4 |
#include <bits/stdc++.h>
using namespace std;
void Fast();
long long mindig(long long x);
long long maxdig(long long x);
long long bpow(long long a, long long b, long long abs);
long long bis(long long ar[], long long l, long long r, long long x);
long long bpow(long long a, long long b, long long modi) {
a %= modi;
... | 2 |
#include<iostream>
using namespace std;
int main() {
int n,k;
string s;
cin >> n >> s >> k;
// 逐次出力.
for(char c:s){
if(c != s[k-1]) cout << '*';
else cout << c;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int x[110], y[110];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
for (int i = 0; i < n; i++) scanf("%d%d", &x[i], &y[i]);
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (x[i] + x[j] <=... | 3 |
#include <bits/stdc++.h>
int n;
long long a, b, c, p;
int main() {
p = 1000000009;
scanf("%d", &n);
a = 1;
b = 2;
c = 4;
for (int i = 1; i < n / 2; i++) {
c = (c * a) % p;
b = (b + c) % p;
a = (a * 2 + 3) % p;
}
printf("%I64d\n", (b * b + 1) * 2 % p);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long int Call_Fun(int i, long long int a, long long int b,
long long int c) {
long long int k = 0;
for (;;) {
if (i == 0 || i == 3) {
if (!b) return k;
b--;
} else if (i == 1 || i == 2 || i == 5) {
if (!a) return k;
... | 3 |
#include <iostream>
using namespace std;
int main(){
int n;cin >> n; string s,t ; cin >>s>>t; long long p[26], m=1e9+7;
for(int i=0; i<26;i++) p[i]=0;
p[s[0]-'a']=1;
for(int i=1; i<n-1;i++) p[s[i]-'a'] = (p[t[i]-'a'] + p[s[i]-'a'])%m;
cout <<p[t[n-1]-'a']<<endl;
}
| 0 |
#include<iostream>
#include<iomanip>
using namespace std;
int num;
void fillNumA( int a[9][9], int n, int i, int j )
{
while( i < n && j >= 0 )
{
a[i][j] = num;
num++;
i++;
j--;
}
}
void fillNumB( int a[9][9], int n, int i, int j )
{
while( i + 1 < n && j - 1 >= 0 )
... | 0 |
#include<iostream>
using namespace std;
int main()
{
int i;
int n,f,cn,a;
while(cin >> n,n)
{
f=cn=0;
for(i=0;i<n;i++)
{
cin >> a;
if(a>=2)
{
f=1;
}
if(a>0) cn++;
}
if(f)
{
cout << cn+1 << endl;
}
else cout << "NA\n" ;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int t[100005] = {};
int main() {
int n, m, a[5], u[5] = {};
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a[1] >> a[2] >> a[3];
for (int j = 1; j <= 3; j++) u[j] = 0;
if (!i) {
for (int j = 1; j <= 3; j++) t[a[j]] = j;
} else {
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long a[100005];
long long b[100005];
signed main() {
cin >> n >> m;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
}
for (long long i = 1; i <= m; i++) {
cin >> b[i];
}
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
if (a[n] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;
const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
inline int toint(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class t>
inline strin... | 4 |
#include <bits/stdc++.h>
const int MAXN = (int)1e2 + 5;
const int MODN = (int)1e9 + 7;
int inf = 0x3f3f3f3f;
using namespace std;
char maps[MAXN][MAXN];
int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
maps[i][j] = '.';
... | 1 |
#include "iostream"
using namespace std;
int main() {
char c[9];
for (int i = 0; i < 9; i++) cin >> c[i];
cout << c[0] << c[4] << c[8] << endl;
} | 0 |
#include<cstdio>
int N;
int opened[100][14];
int profit[100][15];
int main() {
scanf("%d", &N);
for (int i=0;i<N;i++)
for (int j=0;j<10;j++) scanf("%d", &opened[i][j]);
for (int i=0;i<N;i++)
for (int j=0;j<11;j++) scanf("%d", &profit[i][j]);
int res=-(1<<30);
for (int b=1;b<... | 0 |
#include <bits/stdc++.h>
using namespace std;
constexpr long double m_pi = 3.1415926535897932L;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 61;
constexpr long double EPS = 1e-10;
template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
using vector3 = vector<vector2<T>>;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, first[500010] = {0}, tot = 0, totke, pos[500010], tim = 0;
int ma[500010], mb[500010], pre[500010][21] = {0}, dep[500010] = {0};
int p[2000010], totp, pe[500010], tote, fa[500010];
int st[500010], top;
long long mw[500010], mx[500010][21] = {0}, dis[500010] = {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n, x, y, w;
long long javab;
vector<int> a[maxn];
bool mark[maxn];
long long ans[maxn], counter;
vector<int> tmp;
bool lucky(int b) {
bool c = 1;
while (b) {
if (b % 10 != 4 && b % 10 != 7) c = 0;
b /= 10;
}
return c;
}
vo... | 5 |
// B. Toy Blocks
#include <iostream>
#include <algorithm>
#include <numeric>
using namespace std;
using ull = unsigned long long;
int main(){
int t;
cin >> t;
while(t--){
int n;
cin >> n;
ull a[n];
for (auto &el: a) cin >> el;
ull ans = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
int n, m, k, q;
set<int> zbior[nax];
int wjakiejskladowejjestem[nax];
vector<int> skladowe[nax];
map<int, int> krawedzie[nax];
int rozmiar[nax];
void pre() {
cin >> n >> m >> k >> q;
for (int i = 1; i <= n; i++) {
zbior[i].insert(i);
skl... | 6 |
#include<iostream>
using namespace std;
int main(){
char c;
cin>>c;
cout<<++c;;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[110], mx;
const int N = 30;
map<int, int> mem;
int Penu(int now) {
if (!now || mem.find(now) != mem.end()) return mem[now];
register int ans = 0;
register set<int> mex;
for (register int i = 1; i < 31; i++)
if (now >> i) mex.insert(Penu(now & ((1 << i) ... | 3 |
// AOJ 1028 - ICPC: Ideal Coin Payment and Change (ツ妥ヲ5ツ嘉アツ療サツ習ツ嘉ッJ)
#include <iostream>
#include <algorithm>
using namespace std;
int c[6] = {1, 5, 10, 50, 100, 500};
int getNum(int t){
int res = 0;
for(int i=5;i>=0;i--){
res += t/c[i];
t %= c[i];
}
return res;
}
int main(){
int P, N[6];
while(cin >> P,... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << (n / 2) - 1;
} else {
cout << n / 2;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
#pragma GCC target("avx")
const long long MAXN = 1e6 + 7;
vector<vector<long long>> g(MAXN);
vector<vector<long long>> h(MAXN);
long long used[MAXN];
long long used2[MAXN];
vector<long long> ts;
vector<long long> ans;
void dfs(long long u) {
us... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long fact[1000010];
long long S, a, b, N;
long long power(long long n, long long x) {
if (x == 0) return 1;
long long ret;
ret = power(n, x / 2);
ret = ret * ret % mod;
if (x % 2 != 0) ret = ret * n % mod;
return ret;
}
lon... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N=605;
int n,m,x,y,a[N][N],d[N];
double f[N],g[N];
signed main(){
scanf("%d%d",&n,&m);
while (m--){
scanf("%d%d",&x,&y);
a[x][++a[x][0]]=y;
}
f[0]=0;
for (int i=n-1;i;i--){
for (int j=1;j<=a[i][0];j++)f[i]+=f[a[i][j]]/a[i][0];
f[i]++;
}
double ans=f[... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mx = 2750132;
long long done[mx];
vector<long long> pr;
long long idx[mx];
multiset<long long, greater<long long> > a;
long long dv(long long k) {
for (long long i = 2; i * i <= k; i++) {
if (k % i == 0) return k / i;
}
}
int main() {
{
ios ::s... | 4 |
#include <stdio.h>
int main(void){
double max, min;
double h;
max = 0;
min = 100000000;
while(scanf("%lf", &h) != EOF){
if(max < h) max = h;
if(min > h) min = h;
}
printf("%f\n", max - min);
return 0;
} | 0 |
#include<bits/stdc++.h>
#define endl '\n'
#define mt make_tuple
#define pb push_back
#define ff first
#define ss second
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using ld = long double;
const int maxn = 100001;
const ll INF = LLONG_MAX;
const ll mod = 1e9 + 7;
ll POW(ll a, ll b, l... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long k, a, b, ans;
bool f;
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> k >> a >> b;
if ((a < k && b % k) || (b < k && a % k))
cout << -1 << endl;
else
cout << ((a / k) + (b / k)) << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long arr[10002];
void solve(int k, int n1, int t1) {
int tmp = k;
int pos = 0;
int cc = 1;
while (tmp > 0) {
for (int i = 0; i < min(tmp, n1); i += 1) {
if (pos >= n1) {
arr[pos] = max(arr[pos], arr[pos - n1]) + t1;
} else
arr[po... | 4 |
#include<bits/stdc++.h>
/*• __builtin_clz(x): the number of zeros at the beginning of the bit represen- tation
• __builtin_ctz(x): the number of zeros at the end of the bit representation
• __builtin_popcount(x): the number of ones in the bit representation
• __builtin_parity(x): the parity (even or odd) of the number ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int w, h;
int n;
char s[25][25];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int x[25 * 25], y[25 * 25], t[25 * 25];
int X[25 * 25], Y[25 * 25], T[25 * 25];
int flag[25][25], tot;
int chk[25][25], chkn;
int sink;
void End() {
puts("-1");
exit(0);
}
void input() ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int maxN = 512;
int N, IR, IC, R, C;
string cmd;
string bt;
bool grid[maxN][maxN];
int walk[maxN][maxN];
set<int> col[maxN];
set<int> row[maxN];
int cnt;
void turnon(int r, int c) {
if (grid[r][c]) return;
cmd +=... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct V {
int children;
int winning_children;
int res;
};
int main() {
int n;
scanf("%d", &n);
vector<V> Nodes(2 * n);
int N = 2 * n;
int k1, k2;
scanf("%d", &k1);
vector<int> S[2];
S[0] = vector<int>(k1);
for (int i = 0; i < (k1); ++i) scanf("%d", ... | 3 |
#include <iostream>
using namespace std;
int main() {
int a,n;
cin >> n >> a;
cout << (n%500<=a?"Yes":"No") << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int permutation[100];
long long fact[100];
void writeFact(int n) {
fact[0] = 1;
for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
}
void kthPermutation(int n, int i) {
i--;
int j, k = 0;
for (k = 0; k < n; ++k) {
permutation[k] = i / fact[n - 1 - k];
... | 5 |
#include <bits/stdc++.h>
int s[1000005], i, t, k, ans;
char a[1000005];
int main() {
scanf("%s", a);
for (i = 0; a[i]; i++)
if (a[i] != a[i - 1])
s[t++] = 1;
else
s[t - 1]++;
if (a[0] == a[i - 1]) s[0] += s[--t];
for (i = 0; i < t; i++)
if (s[i] == 1)
k++;
else
ans += k /... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
inline bool smin(T &a, const T &b) {
return a > b ? a = b : a;... | 4 |
/*
credits : @CoderAnshu
author : Aryan Agarwal, IIT KGP
created : 21-February-2021 12:17:46 IST
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007; /*more than 1e9 */ /*7 + 1e9*/
// const int32_t M = 9982443... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long tt;
cin >> tt;
while (tt--) {
long long n, i, j;
cin >> n;
map<char, bool> ok;
string str[n + 1];
vector<string> vs;
set<string> s;
for (i = 0; i <... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e6 + 30;
const int MAXN = 1e3 + 2;
const long long INF = 1e9 + 7;
const long long BINF = 1e15;
const int MOD = 1e9 + 7;
const long double EPS = 1e-15;
long long n, m;
long long a[MXN];
long long used[MXN];
multiset<long long> st;
multiset<long long>::iterat... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long t, x, y, p, q, s[100001];
bool check(long long a) { return (a * q - y >= a * p - x && a * p - x >= 0); }
int main() {
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> x >> y >> p >> q;
long long l = 0;
long long r = 1000000005;
while (l < r) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
int main()
{
int n;
cin >> n;
vector<int> now(n);
now[0]=3;
ll ans = 1;
rep(i,n)
{
int foo;
cin >> foo;
an... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
string p, h;
cin >> p;
cin >> h;
map<char, int> wCount;
for (const auto &c : p) {
wCount[c]++;
}
map<char, int> wCountChecker(wCount);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int a, b;
cin >> a >> b;
int diff = min(a, b);
a -= diff;
b -= diff;
int same;
if (0 == a) {
same = 1 == b ? 0 : 0 == b % 2 ? b / 2 : b / 2;
} else {
same = 1 == a ?... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define p 998244353
int MOD(int a){
return (a %= p) >= 0 ? a : a + p;
}
int power(int a, int N){
if(N == 0) return 1;
else if(N % 2 == 0) return power(MOD(a * a), N / 2);
else return MOD(a * power(a, N - 1));
}
int inverse(int a){
return power(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], max = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max) max = a[i];
}
int c = 0, k = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (a[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a, b, r, d;
int main() {
scanf("%d%d%d", &a, &b, &r);
d = r * 2;
if (a >= d && b >= d)
printf("First\n");
else
printf("Second\n");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
std::ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
bool prime(int x) {
if (x == 0 || x == 1) {
return false;
}
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
int main... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, mmz, m, flag = 0;
string s, ss;
char y;
vector<int> v[30];
int p[30];
while (cin >> n) {
for (int i = 0; i < 30; i++) v[i].clear();
for (int i = 1; i <= n; i++) {
cin >> y;
v[y - 'a'].push_ba... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], n, m;
vector<int> v[20];
set<pair<int, int> > myset[20];
set<pair<int, int> >::iterator it;
long long first(int l, int r, int i) {
long long x = (r - l + 1);
return (1LL << i) * ((x * (x + 1)) / 2);
}
int main() {
int i, j;
scanf("%d", &n);
scanf("%... | 5 |
#include <bits/stdc++.h>
using namespace std;
int d[5005][5005];
int l[5005];
int n, m;
vector<int> u[5005];
bool k[5005];
void f(int i) {
for (int j = (0); j < (n); j++) d[i][j] = 1e6;
queue<int> q;
q.push(i);
d[i][i] = 0;
while (!q.empty()) {
int f = q.front();
q.pop();
for (int j : u[f])
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[200006], i, m, ans, k, l, j, q, x, n, ma, mi;
string s;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x)
k++;
else
ans += k;
}
cout << ans << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> isprime;
vector<int> primes;
void sieve(int n) {
isprime.resize(n + 1);
for (int i = 0; i <= n; i++) isprime[i] = 1;
isprime[1] = 0, isprime[2] = 1;
for (int i = 2; i * i <= n; i++)
if (isprime[i])
for (int j = 2; i * j < n; j++) isprime[i * j... | 4 |
//Code by Ritik Agarwal
#include<bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define int long long int
#define loop(i,a,b) for(int i=a;i<b;i++)
#define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 100;
bool t[maxn], tt[maxn];
long long tx = 0, ty = 0;
int main() {
long long n, m, x, y;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> x >> y;
if (!t[x]) {
t[x] = 1;
tx++;
}
if (!tt[y]) {
tt[y] = 1... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long bin(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) return bin((a * a) % 1000000007, b / 2) % 1000000007;
return ((a % 1000000007) * (bin((a * a) % 1000000007, b / 2) % 1000000007)) %
1000000007;
}
void solve() {
long long n, k;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int s[N], t[N], id[N];
int main() {
int n;
scanf("%d", &n);
long long sum = 0;
for (int i = 0; i < n; ++i) scanf("%d", s + i), id[i] = i, sum += s[i];
sort(id, id + n, [](int l, int r) { return s[l] < s[r]; });
for (int i = 0; i < n; ++i) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200110;
long long t[maxn];
int n, k, b, c;
int main() {
scanf("%d%d%d%d", &n, &k, &b, &c);
b = min(c * 5, b);
for (int i = 0; i < n; ++i) {
scanf("%I64d", &t[i]), t[i] += 1e9;
}
sort(t, t + n);
int lx;
long long sum = 0;
long long ans = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(NULL);
cout << (fixed) << setprecision(6);
int n, m;
while (cin >> n >> m) {
if (m == 3) {
if (n == 3)
cout << "0 0\n0 1\n1 0\n";
else if (n == 4)
cout << "0 0\n10 0\n0 10\n1 1\n";
... | 4 |
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
int n,c,i,sum,x,p;
scanf("%d %d",&n,&c);
sum=0;
for(i=0;i<c;i++) {
scanf("%d",&p);
sum+=p;
}
x=sum/(n+1);
if(sum%(n+1)!=0) x++;
printf("%d\n",x);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int solve() {
int n, k;
scanf("%d%d", &n, &k);
if (n < k || k % 3 != 0) return n % 3 == 0;
int index = (n - k + 3) % (k + 1);
return (index == 0) || (index > 1 && (index - 1) % 3 == 0);
}
int main() {
int t;
scanf("%d", &t);
while (t--) solve() ? printf("Bob... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, a0;
a1 = a0 = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == '0')
a0++;
else
a1++;
}
cout << abs(a1 - a0);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
bool path[maxn][maxn] = {0};
vector<int> c[maxn];
bool d[maxn] = {0};
int trace[maxn];
int n, root, preroot;
int res[maxn] = {0};
bool circle = false;
bool incir[maxn] = {0};
void dfs(int i) {
d[i] = true;
if (circle) return;
for (int j = 0; j <... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool check(vector<int> &V, string &s) {
int it = 0;
int left = 0, right = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
left++;
else if (s[i] == ')')
right++;
else
right += V[it++];
if (right > left) return 0;
}
return ... | 1 |
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int N , T , B , L;
while(cin >> N >> T >> L >> B && N){
int flag[101] = {0};
for(int i = 0 ; i < L ; i++){int a; cin >> a; flag[a] = 1;}
for(int i = 0 ; i < B ; i++){int a; cin >> a; flag[a] = 2;}
double dp[111][101]={0};
dp[0][0] = 1.0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int ret(int n);
int main() {
ios_base::sync_with_stdio(0);
int hh = 0, mm = 0, i;
string s;
cin >> s;
for (i = 0; i < 2; i++) {
hh *= 10;
hh += s[i] - '0';
}
for (i = 3; i < 5; i++) {
mm *= 10;
mm += s[i] - '0';
}
while (true) {
if (mm ... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main (void) {
int n; cin >> n;
vector<char> v;
for (int i = 0; i < n; i++)
{
char num; cin >> num;
v.push_back(num);
}
for (int i = 0; ; i++)
{
string str = to_string(i);
#ifdef D
cout << "search num is " << str << endl;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> a;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
a[tmp] = 1;
}
if (a.size() == n)
cout << "YES";
else
cout << "NO";
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.