solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010, P = 998244353;
int n, a[maxn], f[maxn][maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1, greater<int>());
f[1][1] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
int const N = 100000;
map<int, int> mp[N + 1];
int pa[N + 1];
int main(){
int n, m;
scanf("%d%d", &n, &m);
f(i, 1, n + 1)pa[i] = i;
f(i, 1, n + 1)mp[i][i] = 0;
while (m--){
int l, r, d;
sca... | 0 |
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(void){
int n;
while(cin >> n && n != -1){
double x = 1.0, y = 0.0;
for(int i = 1; i < n; i++){
double newx, newy;
newy = x / sqrt(x * x + y * y);
newx = -y / sqrt(x * x + y * y);
x += newx; y += new... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A,B;
cin >> A >>B;
cout << ((A == B) ? A+B : max(A,B)*2-1) << endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INFint = 2147483647;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-9;
int main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
long long ans = INF;
long long ans1 = -INF;
for (long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, int>, pair<long long, int> > mp;
pair<long long, int> cal(long long n, int x) {
if (n == 0) return make_pair(0, 0);
if (n < 10) return make_pair(1, max(0, (int)(x - n)));
pair<long long, int> now = make_pair(n, x);
if (mp.count(now)) return mp[no... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> A, RES;
map<long long int, set<long long int>> EDGES;
vector<long long int> E, P;
long long int SUM = 0;
long long int AA;
vector<long long int> STACK;
vector<long long int> SUMSTACK;
vector<long long int> STACKIDX;
vector<long long int> RETURN;
vector... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
inline int read() {
int x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x;
}
struct Node {
int x;
int y;
int forward;
};
set<int... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 7340033;
int main() {
long long a[31][1001];
long long b[1001];
for (int i = 0; i <= 30; ++i) {
a[i][0] = 1;
for (int j = 1; j <= 1000; ++j) a[i][j] = 0;
}
b[0] = 1;
for (int i = 1; i <= 1000; ++i) b[i] = 0;
for (int i = 1; i <= 30; ++i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int INF = 1e8 + 7;
int n;
int Min[N][20], Max[N][20];
struct Node {
int x, y;
bool operator<(const Node& p) const { return x < p.x; }
} nod[N];
long long sqr(long long x) { return x * x; }
void rmq() {
for (int i = 0; i < n; ++i) {
Min... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int p[maxn], cnt[maxn], d[maxn];
long long sum[maxn];
long long gcd(long long x, long long y) {
if (!y) return x;
return gcd(y, x % y);
}
void add(int &ans, int tmp) { ans = (ans + tmp) % mod; }
int main() {
int n;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b;
cin >> n >> b;
int nums[n];
int sum = 0;
int maxMil = 0;
for (int i = 0; i < n; i++) {
cin >> nums[i];
if (nums[i] > maxMil) {
maxMil = nums[i];
}
sum += nums[i];
}
int diff = maxMil * n - sum;
if (b >= diff) {
... | 1 |
#include <bits/stdc++.h>
const int N = 200001;
using namespace std;
int f(string &s) {
long long int pr = 1;
long long int hash = 0;
for (char c : s) {
hash += (c - 'a' + 1) * pr;
pr = (pr * 33) % 1000000007;
}
return hash % 1000000007;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL... | 2 |
#include <bits/stdc++.h>
using namespace std;
int id[3010][6010], par[600001], cnt;
int fnd(int k) { return par[k] == k ? k : par[k] = fnd(par[k]); }
constexpr int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1, 0},
dy[] = {-1, 0, 1, -1, 1, -1, 0, 1, 0};
int n, m;
vector<int> neighbor(int x, int y) {
vector<int> ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
vector<int> a(5);
string s;
long long q = 0;
for (int i = 1; i < 5; ++i) {
cin >> a[i];
}
cin >> s;
for (int i = 0; i < (int)s.size(); ++i) {
q += a[s[i] - '0'];
}
cout << q;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int bfsz = 1 << 16;
char bf[bfsz + 5];
int rsz = 0;
int ptr = 0;
char gc() {
if (rsz <= 0) {
ptr = 0;
rsz = fread(bf, 1, bfsz, stdin);
if (rsz <= 0) return EOF;
}
--rsz;
return bf[ptr++];
}
void ga(char &c) {
c = EOF;
while (!isalpha(c)) c = gc... | 5 |
#include <bits/stdc++.h>
unsigned A[111], Ai, Q[111], Qi, Ri;
char R[11111][111];
unsigned F() {
unsigned i, m, m2, d;
Qi = m = m2 = d = 0;
for (i = -1; ++i < Ai;) {
if (A[i] == m)
Q[Qi++] = i;
else if (A[i] > m) {
m = A[i];
Q[0] = i;
Qi = 1;
}
}
if (Qi == Ai) return 0;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e7 + 5e6 + 20;
int a[2][5];
long long ans[2][N];
void getAns(int t) {
iota(ans[t], ans[t] + N - 10, 0);
for (int i = 0; i < N - 10; i++) {
for (int j = 0; j < 3; j++) {
if (a[t][j] <= i)
ans[t][i] = max(1ll * ans[t][i],(long long) ans[t][i - a[t][... | 0 |
#include <bits/stdc++.h>
int main() {
int h, a, c;
int H, A;
scanf("%d %d %d", &h, &a, &c);
scanf("%d %d", &H, &A);
int i;
int fightArr[100000];
for (i = 0; H > 0; ++i) {
if (a >= H) {
fightArr[i] = 1;
H -= a;
continue;
}
if (A >= h) {
fightArr[i] = 0;
h += c;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int x,y;
int minx=100000;
for(int i=0;i<n;i++){
cin>>x>>y;
if(y<=m){
minx=min(minx,x);
}
}
if(minx==100000){
cout<<"TLE";
}else{
cout<<minx;
}
}
| 0 |
#include <bits/stdc++.h>
int len = 0;
int cha[200008];
double sum = 0;
int main() {
int i, j, k, n, m, a, x;
scanf("%d", &n);
cha[len++] = 0;
while (n--) {
scanf("%d", &m);
if (m == 1) {
scanf("%d%d", &a, &x);
sum += (a * x);
if (a == len)
cha[len - 1] += x;
else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
class Cht {
vector<pair<long long, long long>> lines;
vector<long double> intersections;
public:
void addLine(long long k, long long b) {
pair<long long, long long> line = {k, b};
if (!lines.empty() && k == lines.back().first) {
if (b >= lines.back().s... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const int UNDEF = -1;
const int INF = 1 << 30;
template <typename T>
inline bool chkmax(T& aa, T bb) {
return aa < ... | 2 |
#include <bits/stdc++.h>
class Solve {
private:
int H, W;
std::vector<std::string> data;
bool is_founded[26]{};
bool is_suspicious()
{
scanf("%d%d", &H, &W);
data.resize(H);
for (auto& e: data) std::cin >> e;
while (true)
{
if (square_exist()) continue;
return alphabet_exist();
}
}
bool alph... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest;
cin >> ntest;
for(int z = 1;z <= ntest; z++)
{
int n;
string a, b;
cin >> n >> a >> b;
bool check = true;
int wrong = 0;
int... | 2 |
#include <bits/stdc++.h>
long long n, m, cap, mod, b[503], dp[503][503], mx;
using namespace std;
int main() {
cin >> n >> m >> cap >> mod;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (long long i = 0; i < n; i++) cin >> b[i];
for (long long p = 0; p < n; p++)
for (long long l = 0; l <= m; l++)
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const long long mod = 1e9 + 7;
int a[N];
int random(int n) { return (int)((long long)rand() * rand()) % n; }
set<pair<int, int> > ans;
void solve() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long qpow(long long a, int b) {
long long res = 1;
for (; b; a = a * a % 1000000007, b >>= 1)
if (b & 1) res = res * a % 1000000007;
return res;
}
int main() {
long long n, m;
cin >> n >> m;
cout << qpow((qpow(2, m) - 1), n) << endl;
return 0;
... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
set<string>s;
while(t--) {
string ss;
cin>>ss;
s.insert(ss);
}
cout<<s.size();
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
char st[N];
vector<int> sta[2][2], d[N];
int ans, n, q, now;
int main() {
scanf("%s", st);
n = strlen(st);
int k = 0, p = 0, m = 0, snow = 0;
for (int i = 0; i < n; i++) {
int p = (st[i] == 'R'), t = 1;
for (int q = p, k = 1; k <= 2... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[10000001];
long long sum;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (n == 1) {
cout << a[1];
return 0;
}
for (int i = 2; i <= n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 2147483647;
int a1[100005], a2[100005], a3[100005], d[100005], b[100005];
int sum = 0, ans[100005], num[100005], n, m;
bool comp(int i, int j) {
return a3[i] < a3[j] || (a3[i] == a3[j] && a2[i] < a2[j]);
}
void init() {
int tmp, i;
scanf("%d%d", &n, &m)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN=5e5+10;
char s[MAXN];
int len,res=0,nxt1[MAXN],nxt2[MAXN];
void cal_nxt(int* nxt)
{
int k=0;
for(int i=2;i<=len;i++)
{
while(k&&s[k+1]!=s[i]) k=nxt[k];
if(s[k+1]==s[i]) k++;nxt[i]=k;
}
}
bool check(int* nxt,int pos)
{
if(!nxt[pos]) return false;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int cnt;
int main() {
int arr[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
for (int i = 0; i < 15; ++i) {
cout << arr[i] << endl;
cin >> s;
if (s == "yes") ++cnt;
if (i < 4 && s == "yes") {
cout << arr[i] * arr[i] << endl... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T &x) {
return x * x;
}
inline long long sqr(int x) { return sqr<long long>(x); }
template <class T>
T binpow(const T &a, long long n) {
return n == 0 ? 1 : sqr(binpow(a, n / 2)) * (n % 2 ? a : 1);
}
long long binpow(long long a, lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
int64_t mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int casi;
cin >> casi;
while (casi--) {
int n, k;
cin >> n >> k;
int arr[n * k];
for (int i = 0; i < n * k; i++) cin >> arr[i];
int64_t sol = 0;
int tmp = n * k - (n +... | 2 |
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define ll long long
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
#define ld long double
ll INF = (1LL << 60);
int mod = 1000000007;
ll H, W;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> H >> W;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a[n], sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sum = a[0] + n - 1;
;
for (int i = 1; i < n; i++) {
sum += (a[i] - 1) * (i + 1);
}
cout << sum;
}
| 1 |
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 2e5;
int n, m;
char col[maxn + 1];
vector<int> g[maxn * 4];
void Add(int u, int v) {
char a = col[u], b = col[v];
int t;
if (a == 'A') {
if (b == 'A') {
t = 0;
} else {
t = 1;
... | 0 |
#include <bits/stdc++.h>
#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;
void Draganov47(string click) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void submit() {
int n;
cin >> n;
... | 3 |
#include <bits/stdc++.h>
int main() {
int n, x1, y1, x2, y2, sum = 0;
scanf("%d", &n);
while (n--) {
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
sum += (x2 - x1 + 1) * (y2 - y1 + 1);
}
printf("%d\n", sum);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int arr[127];
int main() {
string s;
int ans = 0;
cin >> s;
for (int i = 0, n = s.size(); i < n; i++) arr[(int)s[i]]++;
while (true) {
if (arr['n'] >= 3 && arr['e'] >= 3 && arr['t'] >= 1 && arr['i'] >= 1) {
ans++;
arr['n'] -= 2;
arr['e'] -= 3... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
bool passed[101][101];
vector<pair<int,int> > d;
int cnt=0;
// Eº©çÔÉèµÄ¢
void dfs(int x,int y,int left){
// cèª0ÉÈÁ½çJEg
if(left==0)
cnt++;
else{
// »ÝÌ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
int main() {
ios::sync_with_stdio(false);
string s;
vector<int> op, f;
int n, oNeg = 0, oPos = 1;
op.push_back... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-8;
char str[1000010];
int main() {
scanf("%s", str + 1);
int len = (int)strlen(str + 1);
int ans = 0;
int M = 0, last = 0;
for (int i = 1; i <= len; i++) {
if (str[i] == 'M')
++M;
else if (M) {
... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
set <int> m;
int q;
cin>>q;
while(q--)
{
int a;
cin>>a;
if(a==0)
{
int x;
cin>>x;
m.emplace(x);
cout<<m.size()<<endl;
}
else if(a==1)
{
... | 0 |
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namesp... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int a[N];
int getSum(int l, int r) { return a[r] - (l > 0 ? a[l - 1] : 0); }
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) {
a[i] = s[i] == 'I' || s[i] == 'E' || s[i] == 'A' || s[i] == 'O' ||
s[i... | 5 |
#include<cmath>
#include<cstdio>
#define N 3003
using namespace std;
int a[N],i,j,m,n;double b,c,d,e,s,t,x,y;const double p=acos(-1);
int main()
{
for(scanf("%d%d",&n,&m),i=1;i<=n;i++)scanf("%d",a+i);
for(i=1;i<=n;i++)for(j=i+1,s=t=0;j<=n;j++)b=cos(p*(a[i]+a[j])/m+p),c=sin(p*(a[i]+a[j])/m+p),d=cos(2*p*a[i]/m)-b,e=sin... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans;
int A[M... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, t = 0, counter = 0, p1 = 0, p2 = 0;
cin >> N;
int Array[N];
int a = 0, b = N - 1;
for (int i = 0; i < N; i++) {
cin >> Array[i];
}
while (a <= b) {
if (Array[a] >= Array[b]) {
t = Array[a];
a++;
} else {
t = Ar... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ld = long double;
using pii = pair<int, int>;
const ll M = 982451653;
void solve() {
int n, q;
cin >> n >> q;
vector<vi> start(n), end(n);
for (int i = 0; i < q; i++) {
int l, r, x;
cin >> l >> r >> x;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, r, count = 1;
cin >> k >> r;
while (true) {
if ((k * count) % 10 == r || (k * count) % 10 == 0) {
cout << count;
return 0;
}
count++;
}
}
| 1 |
#include<iostream>
using namespace std;
int S,W;
int main(){
cin >> S >> W;
if(S <= W)
cout << "unsafe";
else
cout << "safe";
} | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (true) {
a %= b;
if (a == 0) return b;
b %= a;
if (b == 0) return a;
}
}
bool isB(long long n) {
n = abs(n);
while (n > 0) {
if (n % 10 == 8) return true;
n /= 10;
}
return false;
}
bool isP... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, long long>& a, pair<long long, long long>& b) {
return a.first + a.second > b.first + b.second;
}
void solve() {
long long n, r;
cin >> n >> r;
vector<pair<long long, long long>> pos;
vector<pair<long long, long long>> neg;
while (n--) {... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, m, k;
long long cut;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void exgcd(long long a, long long b, long long& d, long long& x, long long& y) {
if (!b)
d = a, x = 1, y = 0;
else
exgcd(b, a... | 3 |
#include <bits/stdc++.h>
const int maxn = 100000;
int n, dep[maxn + 10], a[maxn + 10], ans = 1;
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; ++i) {
int x;
scanf("%d", &x);
a[dep[i] = dep[x] + 1] ^= 1;
}
for (int i = 1; i <= n; ++i) ans += a[i];
printf("%d", ans);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int arr[n];
set<long long int> s;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
out << "[";
for (auto vi : v) out << vi << ", ";
out << "]\n";
return out;
}
int DX[] = {0, +1, 0, -1, 0};
int DY[] = {+1, 0, -1, 0, 0};
const int MAX_N = 500 + 3;
vector<int> c;
queue<int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
int sum[N << 2], ans[N << 2], trans[N << 2], lmin[N << 2], rmin[N << 2],
lmax[N << 2], rmax[N << 2], pre[N << 2], nxt[N << 2];
void pushup(int p) {
sum[p] = sum[p << 1] + sum[p << 1 | 1];
lmin[p] = min(lmin[p << 1], sum[p << 1] + lmin[p << ... | 3 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const int N = 3e5 + 5;
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int INFi = 0x7f7... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ct = 0;
while (n > 0 && m > 0) {
if (n >= m) {
m++;
n -= 2;
} else {
m -= 2;
n++;
}
if (n < 0 || m < 0) break;
ct++;
}
cout << ct << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
string str;
int n;
ll dp[4005][4005];
int main(){
cin>>str;
n=str.size();
dp[0][0]=1;
ll cnt=0;
for(int i=0;i<n*2;i++){
if(i<n)cnt+=2;
for(int j=0;j<=4000;j++){
if(dp[i][j]==0)continue;
ll ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, k, path[N], dist[N];
vector<int> v[N], r[N];
void getdist(int src) {
for (int i = 1; i <= n; i++) dist[i] = 1e9;
queue<pair<int, int> > q;
q.push(make_pair(0, src));
while (!q.empty()) {
pair<int, int> p = q.front();
q.pop();... | 4 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define MAX 10001
#define INF (1<<29)
int main()
{
int Tc,N;
string s;
cin >> Tc;
while(Tc--)
{
cin >> N >> s;
bool b[2][MAX] = {{}};
for(int i = 0 ; i <= N ; i++)
{
if(i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> t(n + 1);
vector<long long> ff(n + 1);
vector<long long> bb(n + 1);
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
if (n == 1) {
cout << t[1] << endl;
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
namespace output {
void pr(int x) { cout << x; }
void pr(long x) { cout << x; }
void pr(ll x) { cout << x; }
void pr(unsigned x) { c... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
int stable[MAXN + 5], father[MAXN + 5], vis[MAXN + 5];
struct XXX {
int x, sum;
} c[MAXN + 5];
int find(int x) {
if (father[x] == x) return x;
return father[x] = find(father[x]);
}
int cmp(XXX a, XXX b) { return a.sum > b.sum; }
int main() {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 30, Mod = 1e9 + 7;
const long long SQ = 330;
set<long long> G[N];
set<pair<long long, long long> > second;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
long long n, q;
cin >> n >> q;
long long res = 0;
long long ans = 0;
for (int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 9;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, int> > guys;
set<pair<int, int> > alive;
map<pair<int, int>, int> id, in;
map<pair<int, int>, set<pair<int, int> > > adj, back_adj;
map<int, pair<int, int> > back;
for (int i = in... | 2 |
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;typedef vector<int> v;int h,w,k;v x(v a,v b){return a.size()>b.size()?a:a.size()<b.size()?b:max(a,b);}int main(){while(cin>>w>>h&&h){v d[75][75],s;r(i,h)r(j,w){char z;cin>>z;z-='0';if(!(z/10)&&(z||d[i][j].size())){d[i][j].push_back(z);d[i+1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
int flag = 0;
for (int j = 0; j < n; j++) {
if (s[i] == s[j] && j < i) {
flag = 1;
break;
}
}
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l = n;
long long sum = 0;
for (int i = 1; i <= n / 2; i++) {
sum = sum + ((i + l) % (n + 1)) + ((i + l + 1) % (n + 1));
l--;
if (i == n / 2) sum -= (i + l + 1 + 1) % (n + 1);
}
if (n == 1)
cout << "0";
else i... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmax(T &_a, T _b) {
if (_b > _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
bool setmin(T &_a, T _b) {
if (_b < _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
T gcd(T _a, T _b) {
ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
priority_queue < int > pq;
int main() {
int n,m;
cin>>n>>m;
long long cost=0;
for(int i=0;i<n;i++) {
int a;
cin>>a;
pq.push(a);
}
while(m--) {
int a=pq.top();
pq.pop();
pq.push(a/2);
}
for(int i=0;i<n;i++) {
cost+=pq.top();
pq.pop();
}
cout<<cost<<... | 0 |
#include<iostream>
#include<cassert>
using namespace std;
#define N 8
#define FREE -1
#define NOT_FREE 1
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
bool X[N][N];
void initialize()
{
int i;
for(i=0;i<N;i++)
{
row[i]=FREE,col[i]=FREE;
}
for(i=0;i<N;i++)
{
dpos[i]=FREE,dneg[i]=FREE;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
long long max(long long a, long long b) {
if (a > b) return a;
return b;
}
long long gcd(long long a, long long b) {
if (a == 0) return b;
if (b == 0) return a;
return gcd(b, a % b);
}
... | 4 |
#include <bits/stdc++.h>
const int MaxN = 1000000 + 5;
int N, K, L;
int A[MaxN];
std::pair<int, int> F[MaxN];
void init() {
scanf("%d %d %d", &N, &K, &L);
static char s[MaxN];
scanf("%s", s + 1);
for (int i = 1; i <= N; ++i)
if (s[i] >= 'a' && s[i] <= 'z') A[i] = 1;
}
inline bool check(int mid) {
F[0] = s... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
long long dp[101][101][101];
long long choose[101][101];
long long fac[101];
int main() {
int n, m, x;
long long MOD;
cin >> n >> m >> x >> MOD;
if (x > (n + 3) / 2) {
cout << 0 << "\n";
return 0;
}
... | 2 |
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#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 <limits>
#include <climit... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Person {
string name;
int pizza, taxi, another;
};
bool isPizza(string num) {
char ch = num[0];
for (int i = 1; i < num.size(); i++) {
if (num[i] == '-')
continue;
else if (ch - num[i] <= 0)
return false;
else
ch = num[i];
}
... | 2 |
#include <bits/stdc++.h>
//#include <math.h>
using namespace std;
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,x;
scanf("%d%d",&k,&x);
for(int i=x-k+1;i<=x+k-1;++i)printf("%d ",i);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int Q,N,s,m,i;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cin >> Q;
for (;Q--;){
cin >> N;
for(i=0;N>10;++i){
s=10,m=0;
while(s<N){
m=max(m,(N/s)*(N%s));
s*=10;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
char mat[1002][1002];
int mincost[1002][1002];
deque<pair<int, int> > d;
int xa, ya, xb, yb;
bool viz[1002][1002];
int ox[] = {-1, 0, 1, 0};
int oy[] = {0, 1, 0, -1};
bool gut(int L, int C) {
if (!L || L > n) return 0;
if (!C || C > m) return 0;
return 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
namespace {
const int N = 250005;
int n, deg[N], lim, vis[N];
long long dp[N][2];
vector<pair<int, int> > G[N];
vector<int> buckvis[N], buckdel[N];
struct Dat {
multiset<long long> st;
long long sum;
Dat() { sum = 0; }
void insert(long long x) {
st.insert(x);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
int n, i;
scanf("%d", &n);
int ans = 0x3f3f3f3f;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (i = 1; i + n / 2 <= n; i++) {
ans = min(ans, a[i + n / 2] - a[i]);
}
printf("%d\n", ans);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int T, q, i, x;
long long p, ans;
inline void upd(int x) {
long long p = ::p;
int q = ::q;
for (; p % q == 0; p /= x)
;
ans = max(ans, p);
}
inline void factor(int x) {
for (i = 2; i * i <= x; ++i)
if (x % i == 0)
for (upd(i); x % i == 0; x /= i)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
s << '{';
for (int i = 0; i < v.size(); ++i) s << (i ? "," : "") << v[i];
return s << '}';
}
template <typename S, typename T>
ostream& operator<<(ostream& s, pair<S, T>& p) {
return s << "(" << p... | 3 |
// template version 1.14
using namespace std;
#include <bits/stdc++.h>
// varibable settings
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int M, F, B;
cin >> M >> F >> B;
if(M + F < B) {
cout << "NA" << endl;
} else {
cout << max(0, B - M) << endl;
}
return (0);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
char ch = getchar();
register long long ret = 0;
while (!(ch >= '0' && ch <= '9')) ch = getchar();
while (ch >= '0' && ch <= '9')
ret = (ret << 3) + (ret << 1) + (ch ^ 48), ch = getchar();
return ret;
}
long long n, k, m;
long long yu... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, p1, p2, p3, t1, t2;
cin >> n >> p1 >> p2 >> p3 >> t1 >> t2;
long long ans = 0, p = -1;
for (int i = 0; i < n; i++) {
lo... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main(void){
int x,a,b;
cin>>x>>a>>b;
if(-a+b<=0)
cout<<"delicious"<<endl;
else if(-a+b<=x)
cout<<"safe"<<endl;
else
cout<<"dangerous"<<endl;
} | 0 |
#include <bits/stdc++.h>
#pragma GCC optimizer("O3")
#pragma GCC target("sse4")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int h = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '<') {
if (s[i + 1] == '/') h--;
for (int i = 0; i < 2 * h; i++) cout << " ";
if (s[i + 1] == '/')
cout << s.substr(i, 4) << endl;
else... | 2 |
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 1e5 + 7;
int a[N], b[N], pre[N], suf[N], len[N][2];
vector<int> up, down;
int get_l(vector<int> &v, int x){
int p = lower_bound(v.begin(... | 2 |
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long inf = 1ll << 62;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int b[100006], l[100006], u[100006];
int dif(int n, int x) {
return max((x - b[n])*l[n], (x - b[n])*u[n]);
}
s... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.