solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, aib[200002], x;
long long poz[200002];
long long lol[200002];
void update(long long aib[], long long poz, long long val) {
for (long long i = poz; i <= n; i += (i & -i)) aib[i] += val;
}
long long query(long long aib[], long long poz) {
long long sum = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int p[] = {2, 3, 5, 7, 11};
int a[1000000], cnt[5], n, lmt;
void dfs(int x, int pre) {
if (x > lmt) return;
if (x > 1) a[n++] = x;
for (int i = pre; i < 5; ++i) dfs(x * p[i], i);
}
bool check(int k) {
memset(cnt, 0, sizeof(cnt));
for (int i = 0; i < k; ++i)
fo... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,k,a;
cin >> n >> k;
vector<ll> cnt(k+1);
cnt[0] = 1;
for(int i = 0; i < n; ++i){
cin >> a;
ll tmp = 0;
for(int j = k; j >= k-a; --j) tmp = (tmp+cnt[j... | 0 |
#include <iostream>
using namespace std;
int main(){
int n,t,c[200],a[200],i,ans=10000;
cin >> n >> t;
for(i=0;i<n;i++){
cin >> c[i] >> a[i];
if(a[i]>t) continue;
ans = min(ans,c[i]);
}
if(ans!=10000){
cout << ans << endl;
}else{
cout <<"TLE" << endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n - 4) / 2;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
if (n > 1) {
if (n == 2 && a[0] == a[1])
cout << -1 << endl;
else {
for (i = 0; i < n - 1; i++) {
if (a[i] < a[i + 1]) break;
}
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int n = s.size();
long long int a[n];
for (int i = 0; i < n; i++) {
a[i] = s[i] - '0';
}
long long int sum = 0, ans = 0, p = 1;
for (long long int i = n - 1; i >= 0; i--) {
long long int k =
(((i * (... | 3 |
#include <bits/stdc++.h>
using namespace std;
enum { North, East, South, West };
int mi[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int mj[] = {0, 1, 0, -1, 1, 1, -1, -1};
class node {
public:
int o, x, y, v;
node(){};
node(int _o, int _x, int _y, int _v) { o = _o, x = _x, y = _y, v = _v; }
};
const int MN = 101;
stack<nod... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, d[1001], a = 1;
string s;
int main() {
cin >> s;
n = s.size();
for (int i = n - 1; i >= 0; i--) {
d[i] = 1;
for (int j = i + 1; j < n; j += 2)
if (s[j] == s[i] && d[j] >= d[i]) a = max(a, d[i] = d[j] + 1);
}
cout << a;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[305];
string get(int x) {
string temp = "";
while (x > 0) {
temp += min(9, x) + '0';
x -= 9;
}
reverse(temp.begin(), temp.end());
return temp;
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> ... | 3 |
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w"... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int n, k, lg[1 << N];
long double p[N], ps[1 << N], dp[1 << N];
vector<int> opt_mask;
int32_t main() {
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> p[i];
int cnt = 0;
for (int i = 0; i < n; i++)
if (p[i] == 0) cnt++;
k = min(k, n - cnt);... | 3 |
#include <iostream>
#include <map>
#include <cstring>
using namespace std;
#define mk make_pair
int main(){
map<char, string> former;
former['A'] = "00000";
former['B'] = "00001";
former['C'] = "00010";
former['D'] = "00011";
former['E'] = "00100";
former['F'] = "00101";
former['G'] = "00110";
former['H'] = "... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, sol = 0, modul = 1000000007;
vector<long long> parent, depth;
long long where(long long pos) {
if (parent[pos] == -1) return pos;
long long a = depth[pos];
long long b = parent[pos];
long long c = where(parent[pos]);
parent[pos] = c;
depth[pos] = (a... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int c = 0;
void bfs(map<long long int, vector<long long int> > &map, vector<bool> &visited,
long long int x) {
queue<long long int> q;
q.push(x);
visited[x] = true;
while (!q.empty()) {
long long int y = q.front();
q.pop();
for (long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
a = a - b;
int k = abs(a);
if (k > c && a > 0)
cout << '+';
else if (k > c && a < 0)
cout << '-';
else if (c == 0 && a == 0)
cout << 0;
else
cout << '?';
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
cout << max(n, m) - 1 << ' ' << min(n, m);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const long long INF = 1e18;
int main() {
c... | 2 |
#include<iostream>
#include<algorithm>
#include<functional>
#include<climits>
using namespace std;
template<class S=int, class T=std::less<S>, S nil=INT_MAX>
class RMQ2D{
int h,w;
S *datrmq;
mutable int xs,xe;
static int calcsize(int n){
int res=1;
while(res<n)res<<=1;
return res;
}
void xbuild(int y,in... | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace mcf {
const int N = 600;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct Edge {
int v, r;
long long f, c, p;
};
vector<Edge> adj[N];
int sz[N];
long long mc;
vector<Edge> mcf_edges;
void init(int n = N) {
mc = 0;
fill(sz, sz + n, 0);
fill(adj, adj + n, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 105, MM = 2017;
int n, m, es[MM], ee[MM];
bool seen[MM], mk[MN];
vector<pair<int, int> > adj[MN];
vector<int> vec;
int dfs(int s) {
mk[s] = true;
int ret = 1;
for (auto x : adj[s])
if (!mk[x.first] && !seen[x.second]) ret += dfs(x.first);
return r... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<string> vs;
string s;
for (int i = (int)0; i < (int)N; i++) {
cin >> s;
vs.push_back(s);
}
long long int ans = 1;
for (int i = (int)0; i < (int)M; i++) {
set<char> st;
for (int j = (int)0; j < (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct lichao {
int l, r;
long long A, B;
lichao() : l(0), r(0), A(0), B(-0x7fffffffffffffffLL) {}
} tree[3 << 20];
const int MAX = 1e9, SZ = 1 << 19, MAX_SIZE = 1 << 20;
int op, node_cnt = 2 * SZ, T[300000];
vector<pair<int, int>> query;
char buf[MAX_SIZE], obuf[MAX_... | 6 |
#include<iostream>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
cout<<(a+b-1)/b<<endl;
} | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long MAXN = 1123456;
const long long N = 1e5;
const long long inf = 3e18;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100020], p[100020], o[100020];
inline bool cmp(const int x, const int y) { return a[x] < a[y]; }
int main(void) {
int n, m;
int i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) p[i] = i;
sort(p + 1, p + n + 1, cm... | 2 |
#include <cstdio>
int main() {
int N;
scanf("%d", &N);
printf("%lf\n", (((N+1)/2)*1.0) / N);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int solve = 0;
int main() {
int n;
scanf("%d", &n);
int cap[n];
for (int i = 0; i < n; i++) {
scanf("%d", &cap[i]);
}
int idx = n - 1;
for (int i = n - 1; i >= 0; i--) {
idx = min(idx, i);
if (idx > i - cap[i]) {
solve += min(idx, idx - i + c... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[2000010], str[2000010], vis[50];
int main() {
int n, m, len, loc, maxc = -0x3f3f3f3f, maxi = -0x3f3f3f3f, last = 0, pos = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str >> m;
last = 0;
pos = 0;
len = strlen(str);
for (int i = 0; i < l... | 3 |
#include <iostream>
using namespace std;
int main()
{
double v ;
while(cin >> v)
{
int N=1;
while(1)
{
int y=N*5-5;
if(v*v<=19.6*y) break;
else N++;
}
cout << N << '\n' ;
}
} | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005,mod=1e9+7;
int n,a,b;
ll f[N],c[N][N],dp[N][2];
ll C(int n,int m)
{
if(m==0||n==m) return 1;
if(m==1) return n;
if(c[n][m]) return c[n][m];
return c[n][m]=(C(n-1,m-1)+C(n-1,m))%mod;
}
ll qpow(ll a,ll n)
{
ll ans=1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110000;
const int inf = 1 << 20;
int a[N], b[N];
int main() {
int n, m;
int i, j;
cin >> n >> m;
int cnt = 1;
if (m % 2 == 1) {
a[(m + 1) / 2] = cnt++;
i = (m + 1) / 2 - 1;
j = (m + 1) / 2 + 1;
} else {
i = m / 2;
j = m / 2 + 1;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long int exp(int a, int b) {
if (b == 1) return a;
return ((long long int)exp(a, b - 1) * a) % MOD;
}
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
if (k > 2 && k < n && k % 2 == 1)
printf("%d\n", m * m);
else if (k >... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, i;
cin >> t;
for (i = 0; i < t; ++i) {
long long int n;
cin >> n;
long long int cnt2 = 0, cnt3 = 0, cnt5 = 0;
while (n % 2 == 0) {
n /= 2;
cnt2++;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 10;
int N, M;
vector<int> adj[MAXN];
int ans[MAXN];
priority_queue<pair<int, int> > pq;
int deg[MAXN];
void fix(int x) {
deg[x] = 0;
for (int y : adj[x]) {
deg[x] += (ans[y] == ans[x]);
}
pq.push(pair<int, int>(deg[x], x));
}
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
getline(cin, s);
int c = 0;
for (int i = 0; i < s.size(); i++) {
int code = int(s[i]), k = 128, ans = 0;
while (code > 0) {
ans += (code % 2) * k;
k /= 2;
code /= 2;
}
cout << (256 + c - ans) % 256 << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, n1, n2;
vector<int> v1, v2;
int resh[100009];
int resa[100009];
map<int, int> home, away;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> n1 >> n2;
v1.push_back(n1);
v2.push_back(n2);
home[n1]++;
away[n2]++;
}
for (in... | 2 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps = 1e-9;
int N;
bool check(const vector<pair<ld, ld>>&cs, const ld amid) {
map<ld, int>mp;
for (auto c :... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const double PI = acos(-1.);
const int N = 200000 + 5;
int n, a[N], w[N];
int din[N], dot[N], fot[N];
vector<int> G[N];
void dfsd(int u, int f) {
int i, v;
for (i = 0; i < G[u].size(); i++) {
v = G[u][i];
if (v == f) continue;
... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int N = 3005;
char s[N];
int main() {
int i, n, last = 1;
static int b[260];
b[(int)'a'] = b[(int)'e'] = b[(int)'i'] = b[(int)'o'] = b[(int)'u'] = 1;
scanf("%s", s + 1);
n = strlen(s + 1);
for (i = 1;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long N, Q, current_answer = 0, BLOCK_SIZE = 450;
long long cnt[1000005], answers[maxn], arr[maxn];
struct Query {
int left;
int right;
int pos;
bool operator<(const Query &q) const {
if (left / BLOCK_SIZE != q.left / BLOCK_SIZE) re... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
bool pre[1000005][26];
string T[200002];
ll ans;
struct trie {
trie *son[26];
int sum[26];
trie() {
for (int i = 0; i < 26; i++) son[i] = NULL, sum[i] = 0;
}
} * root;
bool cmp(const string &a, const string &b) { retu... | 0 |
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator << (ostream& os, const vector<T>& v) { os << "["; for (int i=0; i<v.size(); i++) { os << v[i]; if (i < v.size() - 1) os << ", "; } return os << "]"; }
constexpr size_t MAX_N = 100001;
int N;
int K;
int T[MAX_N];
int main() {
cin... | 0 |
#include <bits/stdc++.h>
using namespace std;
void Get_Val(int &Ret) {
Ret = 0;
char ch;
while (ch = getchar(), ch > '9' || ch < '0')
;
do {
(Ret *= 10) += ch - '0';
} while (ch = getchar(), ch >= '0' && ch <= '9');
}
const int Max_N(55);
const int Max_R(5050);
int N, R, F[Max_N], S[Max_N], P[Max_N], ... | 3 |
#include<iostream>
#include<vector>
using namespace std;
int a[20],n;
bool solve(int i,int m){
int res;
if(m==0){
return true;
}
if(i>=n){
return false;
}
return solve(i+1,m) || solve(i+1,m-a[i]);
}
int main(){
int q;
int m;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>q;
for(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n;
multiset<long long> st;
vector<long long> vect;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
vect.push_back(a);
}
long long delta = 0;
for (long l... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, flag, sum, cnt, d, i;
cin >> t;
while (t--) {
string s;
cin >> s;
flag = 0;
sum = 0;
cnt = 0;
for (i = 0; i < s.size(); i++) {
d = s[i] - '0';
sum = sum + d;
if (d == 0) flag = 1;
if (d % 2 == 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
bitset<2000002> b;
int sum,k;
int main() {
int n,V;
scanf("%d",&n);
b[0]=1;
while(n--) {
int v;
scanf("%d",&v);
b|=b<<v;
sum+=v;
}
int i=(sum)/2+1;
while(i--) if(b[i]) {k=sum-i;break;}
printf("%lld",k);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int A, B;
cin >> A >> B;
cout << 6 - A - B << '\n';
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
const int N=605;
int n,dis[N],vis[N],Dis[N];
vector<pair<int,int>> e[N];
void dijkstra(int s){
memset(dis,0x3f,sizeof(dis));
dis[s]=0;
for(int i=1;i<=n;++i) vis[i]=0;
for(int T=1;T<=n;++T){
int u=0;
for(int i=1;i<=n;++i)
if(!vis[i]... | 4 |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
#define N 105
#define ll long long
#define in(l,n) for(int i=l;i<=n;i++)
int n,q,a[N],b[N],c[N],x[N];
ll sumb[N];
ll dp[N][N*N];
const int mod=1e9+7;
int main(){
scanf("%d",&n);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool isPrime[1000005] = {false};
vector<long long> prm;
vector<long long> SPF(1000005);
void sieve() {
isPrime[1] = isPrime[0] = 0;
long long i;
for (i = 2; i < 1000005; ++i) isPrime[i] = 1;
for (i = 2; i * i < 1000005; ++i) {
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
int n, sum, in;
void solve() {
cin >> n;
sum = 0;
for (int i = 0; i < n; ++i) {
cin >> in;
if (in <= 2048) {
sum += in;
}
}
cout << ((sum >= 2048) ? "YES" : "NO") << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
char ch;
x = 0;
bool fl = false;
while (!isdigit(ch = getchar())) (ch == '-') && (fl = true);
for (x = (ch ^ '0'); isdigit(ch = getchar()); x = x * 10 + (ch ^ '0'))
;
(fl == true) && (x = -x);
}
template <class T>
in... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1010];
vector<int> vis(1010, 0);
vector<int> dist1(1010, 1000000007);
vector<int> dist2(1010, 1000000007);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, s, t;
cin >> n >> m >> s >> t;
int a, b;
vector<pair<int, int>> v;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int N; cin >> N;
string A, B, C; cin >> A >> B >> C;
int ans = 0;
for(int i=0; i<N; i++){
if(A[i]==B[i] && B[i] == C[i]) continue;
else if(A[i]==B[i] || B[i]==C[i] || C[i]==A[i]) ans+=1;
else ans+=2;
}
cout << an... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int div_floor(const long long int &a, const long long int &b) {
return a / b - (((a ^ b) < 0) and a % b);
}
long long int div_ceil(const long long int &a, const long long int &b) {
return a / b + (((a ^ b) >= 0) and a % b);
}
vector<int> parent;
vector<int> cn... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
int n;
long long k;
int a[11111], b[11111];
void basic() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int WZP = 6666666;
char LZH[WZP], *SSS = LZH, *TTT = LZH;
inline char gc() {
if (SSS == TTT) {
TTT = (SSS = LZH) + fread(LZH, 1, WZP, stdin);
if (SSS == TTT) return EOF;
}
return *SSS++;
}
inline int read01() {
char s = gc();
for (; s < '0' || s > '1... | 6 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define MAXN 15
#define INF 0x3F3F3F3F
int v[MAXN][MAXN], n, m, x, y, z;
int c[1 << MAXN][MAXN], f[1 << MAXN][MAXN];
int main(){
scanf("%d%d", &n, &m);
for(int i = 0;i < m;i++){
scanf("%d%d%d", &x, &y, &z);
x--;y--;
v[x][y] = v[y][x] = z;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
int readint() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
int n, m;
int a[1024];
priority_queue<pair<int, int> > q;
int main(void) {
in = stdin;
out = stdout;
fscanf(in, "%d %d", &n, &m);
for (int i = 0; i < m; i++) fscanf(in, "%d", &a[i]);
vector<int> answer;
for (int first = 0; first < m; first++... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Tree {
long long x, height;
bool operator<(const Tree& b) const { return x < b.x; }
} q[105005];
const long long INF = 0x3f3f3f3f3f3f3f3f;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &q[i].x, &q[i].height);
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 5e5 + 5, MXC = 1 << 20;
int n, p[MXN][2];
vector<pair<int, int> > adj[MXC];
bool vis[MXC];
vector<int> ans;
void dfs(int u) {
vis[u] = 1;
for (auto& p : adj[u])
if (!vis[p.first]) dfs(p.first);
}
int build(int m) {
for (int i = (0); i <= (m); ++i) ... | 6 |
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N (100009)
#define MOD (1000000007);
using namespace std;
long long n,a,b,r,sum,s[N],f[N];
int main()
{
scanf("%lld%lld%lld",&n,&a,&b);
if (a>b) swap(a,b);
for (int i=1; i<=n; ++i)
scanf("%lld",&s[i]);
for (int i=3; i<=n; ++i)
if (s[i]-s[i-2]<a){pu... | 0 |
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
vector<char> v;
for (int i = s.length() - 1; i >= 0; --i)
if (v.empty() || v.back() <= s[i]) v.push_back(s[i]);
return string(v.rbegin(), v.rend());
}
int main() {
string s;
cin >> s;
cout << solve(s);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
long long dip;
cin >> n >> k;
if (n <= k)
dip = 0;
else
dip = n / (2 * (k + 1));
cout << dip << " " << k * dip << " " << n - dip * (k + 1);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[505], dp[505][505];
signed main() {
long long n;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i], dp[i][i] = 1;
for (long long le = 1; le < n; le++) {
for (long long l = 1; l + le <= n; l++) {
long long r = l + le;
dp[l][r] = INT... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MAX_N = 6e5 + 5;
void solve() {
long long n;
cin >> n;
if (n == 1)
cout << -1;
else {
long long k = n;
k++;
while (k % 4 != 0) k++;
cout << k / 2 << " " << 2;
}
}
int main() {
ios_base::sync_with_std... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }
const int MAXN = 1 << 19, MOD = 924844033;
LL modpow(LL a, int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MM = int(1e4) + 5;
long long m, n, i, j, x, y, t, ans, a[MM], m1, m2, u, v, s;
void xuli() { ans = s * 2 + max(0 * 1ll, m - n) * (m1 + m2); }
void xuat() {
if (n <= 2 || m < n)
cout << -1 << endl;
else {
cout << ans << endl;
for (i = 2; i <= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
if (y == 0) return 1ll;
if (y % 2)
return (x % 1000000007 * power(x, y - 1) % 1000000007) % 1000000007;
else
return power((x * x) % 1000000007, y / 2) % 1000000007;
}
set<string> ans;
int main() {
ios_base::sync_wi... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
bool visited[30000 + 10];
int adj[30000 + 10];
void DFS(int s) {
visited[s] = true;
if (!visited[adj[s]]) DFS(adj[s]);
}
int main() {
int temp;
cin >> n >> t;
for (int i = 1; i < n; i++) {
cin >> temp;
adj[i] = i + temp;
}
DFS(1);
if (visit... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
vector<ll> width = {1LL};
ll solve(ll s1, ll s2, ll l1, ll l2, int level){
if (level == 0) return abs(l1-l2);
ll w = width[level-1];
if (s1/w != s2/w) {
return abs(s1-s2) + abs(l1-l2);
... | 0 |
#include <bits/stdc++.h>
inline int inc(int x, int v, int mod) {
x += v;
return x >= mod ? x - mod : x;
}
inline int dec(int x, int v, int mod) {
x -= v;
return x < 0 ? x + mod : x;
}
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int _, __, ___;
using namespace std;
template <typename T>
inline void read... | 5 |
#include <cstdio>
#include <vector>
#include <algorithm>
#define STR_MAX 100000
using namespace std;
vector<int> pos[26];
long long int cycl=0,p=0,N;
int main(){
char str[STR_MAX+1];
scanf("%s",str);
for(int i=0;str[i] != '\0';i++){
pos[str[i]-'a'].push_back(i+1);
N++;
}
scanf("%s",str);
for... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int n, k, q;
int a[MAXN], b[MAXN];
int main() {
scanf("%d%d%d", &n, &k, &q);
for (int i = 1; i <= n; i++) {
int l, r;
scanf("%d%d", &l, &r);
a[l]++;
a[r + 1]--;
}
for (int i = 1; i <= 200000; i++) {
a[i] += a[i - 1];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int act = 'a', next, sum = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
next = s[i];
sum += min(abs(act - next), 26 - abs(act - next));
act = next;
}
cout << sum << '\n';
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
string t = s.substr(0, n / 2);
if (s == t + t) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
if (n % 2 == 0) {
m = n / 2 + 1;
cout << m << endl;
for (int i = 1; i <= n / 2; i++) {
cout << "1 " << i << endl;
}
for (int i = 1; i <= n / 2; i++) {
cout << m << ' ' << i << endl;
}
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1E6 + 10;
long long read() {
long long a = 0;
char b = 1, c;
do
if ((c = getchar()) == 45) b = -1;
while (c < 48 || c > 57);
do a = (a << 3) + (a << 1) + (c & 15);
while ((c = getchar()) > 47 && c < 58);
return a * b;
}
void write(long long x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dcmp(long double x, long double y) {
return fabs(x - y) <= 1e-9 ? 0 : x < y ? -1 : 1;
}
const int MAX = 5e5 + 10;
const long long MOD = 1e9 + 7;
class UnionFind {
private:
vector<int> p, rank, setSize;
int numSets;
public:
UnionFind(int N) {
setSize.assig... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int num[100050];
int s[100050];
int t[100500];
int main() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
s[0] = num[0];
for (int i = 1; i < n; i++) s[i] = s[i - 1] + num[i];
s[n] = 0;
for (int i = n - 1; i >= ... | 3 |
#include <cstdio>
#define max(a,b) ((a) > (b) ? (a) : (b))
int N,a,b,t,r[21][21]={0},dp[21]={0};
int l=0;
int rec(int loc, int bef){
int tmp = -1;
dp[loc] = -1;
for(int i = 1; i <= N; i++){
if(r[loc][i] > 0 && dp[i] == 0){
int t2 = rec(i,loc);
tmp = max(tmp,t2);
}
}
if(tmp == -1)
return 0;
dp[loc] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, r = 0, g = 0, b = 0;
string s;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r++;
else if (s[i] == 'G')
g++;
else
b++;
}
if (r == n) {
cout << "R";
return;
}
if (b == n) {
cout <... | 2 |
#include <bits/stdc++.h>
using namespace std;
void file(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
template <typename Tp>
void read(Tp &x) {
int fh = 1;
char c = getchar();
x = 0;
while (c > '9' || c < '0') {
if (c == '-') {
fh = -1;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
double prob[2002][2002];
int main() {
int n, t;
double p;
cin >> n;
cin >> p;
cin >> t;
prob[0][0] = 1;
for (int i = 1; i <= t; i++) {
prob[i][0] = 0;
prob[0][i] = prob[0][i - 1] * (1 - p);
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= t... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
bool operator<(const point &o) const {
return x < o.x || x == o.x && y < o.y;
}
} p[200000];
int main() {
int n, k;
scanf("%d%d", &n, &k);
if (k >= n) {
printf("-1\n");
return... | 6 |
#include <iostream>
#include <cstdio>
#include <map>
#define reep(i,n,m) for(int i=(n);i<(m);i++)
#define rep(i,n) reep(i,0,n)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
int main(){
ll H,W,N;
cin >> H >> W >> N;
map<pii,ll> num;
rep(i,N){
int x,y;
cin >> y >> x;
y--;
x--;
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int id;
int x, y;
} a[3];
bool cmp(node xx, node yy) { return xx.y > yy.y; }
char s[505][505];
int main() {
int sum = 0;
for (int i = 0; i < 3; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
a[i].id = i;
... | 4 |
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
int main(void) {
ll i, j, k, h, w, l;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
char dir[6] = "NESW";
while( 1 ) {
ll x, y, d, cycle;
scanf("%lld%lld%lld", &h, &w, &l);
if(!h && !w && !l) break;
ll a[h][w][4];
char c[h][w + 10];
f... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=(1<<18)+10;
int n,k,s,t,m;
vector<int> a;
ll C[55][55],ways[55];
ll cnt[maxn... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, d, a[1007], c[1007], ans[1007];
int sum = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
cin >> n >> m >> d;
for (int i = 1; i <= m; i++) {
cin >> a[i];
sum += a[i];
c[i] = a[i];
}
for (int i = m; i >... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m, k;
cin >> n >> m >> k;
k = min(k, m - 1);
vector<long long int> v(n);
for (long long int(i) = (0); (i) < (n); (i)++) cin >> v[i];
long long int gg = 0;
for (long long... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 4e3 + 10;
const long long mod = 1e9 + 7;
const int INF = 1e9;
inline long long bpow(long long t, long long n) {
long long ans = 1;
while (n > 0) {
if (n & 1) ans = (ans * t) % mod;
t = (t * t) % mod, n >>= 1;
}
return ans;
}
unordered... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long _t, x, y, k;
cin >> _t;
while (_t--) {
int flag = 0;
cin >> x >> y >> k;
if (k - max(x, y) & 1) flag = 1;
if (x > k || y > k)
cout << -1 << endl;
else {
if (flag) {
if ((x + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int N = 1000000007;
void solve() {
int a, b, c, d;
cin >> b >> a >> c >> d;
cout << (c - 1) / a + b / a - d / a << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55, Ti = 20005;
struct edge {
int v;
double w;
int nxt;
} e[N * 2];
int hd[N], cnt, dis[N][N], n, m, T, X, L, C, R[6 * Ti];
void adde(int u, int v, int w) {
e[++cnt] = (edge){v, (double)w, hd[u]}, hd[u] = cnt;
}
double F[N][2 * Ti], P[N * 2][2 * Ti], G... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n,x;
int main(){
cin>>n;
for(int i=0;i<n;i++){
cin>>x;
if(x%2) continue;
else if(x%3==0 || x%5==0) continue;
else{
cout<<"DENIED";
return 0;
}
}
cout<<"APPROVED";
return 0;
} | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.