solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000005;
const long long M = 28;
long long n, a[N], b[N], ans, tans;
signed main() {
ios::sync_with_stdio(false);
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
for (long long k = 0; k < M; k++) {
for (long long i = 1; i <= n; i++)... | 2 |
#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
const long long inf=101010101010101ll;
const int N=1000005;
int n,i,j,k,f[N],m;
int g[1005][1005],cnt[N],siz[N];
struct str{
int u,v,w;
}e[N];
vector<int> t[N],p;
bool cmp(str a,str b)
{
return a.w<b.w;
}
int Find(int x)
{
return f[x]?f[x]=Find(f[x]... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = (1e-7);
const ll INF =(1e9);
const double PI = (acos(-1));
const ll MOD = ll(1e9) + 7;
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n; i > -1; i--)
#define FOR(i, a, b) fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, num[200005];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
if (num[i] != 0) num[i] = 1e9 + 5;
}
for (int i = 0; i < n; i++) {
if (num[i] == 0) {
for (int j = i - 1, k = 1; j >= 0; j--, k++) {
if ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, i;
float m;
scanf("%d %f", &n, &m);
float mi, c[10000], a, b;
for (i = 0; i < n; i++) {
scanf("%f %f", &a, &b);
c[i] = a / b;
}
mi = c[0];
for (i = 1; i < n; i++) {
if (c[i] < mi) mi = c[i];
}
printf("%.8f", mi * m);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[5005], ans[5005], id[5005], tot, book[5005];
signed main() {
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i];
for (long long i = 1; i <= n; i++) {
for (register long long j = 1; j < i; j++) {
long long x = a[i] * a[j];
if (x <= ... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
int ch = getchar(), f = 1;
while (!isdigit(ch) && (ch != '-') && (ch != EOF)) ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = get... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, dx, dy, cnt[1000100];
int main() {
scanf("%d%d%d%d", &n, &m, &dx, &dy);
map<int, int> tocnt;
int tmpx = 0, tmpy = 0;
for (int i = 0; i < n; ++i) {
tocnt[tmpx] = tmpy;
tmpx += dx, tmpy += dy;
tmpx %= n;
tmpy %= n;
}
for (int i = 0; i < m... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void PV(T a, T b) {
for (T i = a; i < b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void chmin(T &t, T f) {
if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
if (t < f) t = f;
}
const int inff = 0x3f3f3f3f;
const int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int size = 2e6 + 7;
int arr[size];
void fill() {
long long a = 1, b = 0, c = 0;
for (int i = 2; i < size; i++) {
b = a;
a += c * 2 + (i % 3 == 1);
c = b;
a %= 1000000007;
arr[i + 1] = (b * 4) % 1000000007;
}
}
int solve() {
int n;
cin >> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double eps = 1e-11;
const int _mod = 1000000;
const int save[10][4] = {{0}, {0}, {6, 2, 4, 8}, {1, 3, 9, 7}, {6, 4},
{0}, {0}, {1, 7, 9, 3}, {6, 8, 4, 2}, {1, 9}};
int todigit(char c) { return (isdigit(c)) ? ... | 1 |
#include<bits/stdc++.h>
typedef long long LL;
#define pb push_back
const LL maxn=1e5+9;
LL Read(){
LL x(0),f(1); char c=getchar();
while(c<'0' || c>'9'){
if(c=='-') f=-1; c=getchar();
}
while(c>='0' && c<='9'){
x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
}return x*f;
}
void Chkmax(LL &x,LL y){
if(y>x) x=y;
}
LL n... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct modint {
int n;
modint() : n(0) {}
modint(int n) : n(n) {}
};
modint operator+(modint a, modint b) {
return modint((a.n += b.n) >= mod ? a.n - mod : a.n);
}
modint operator*(modint a, modint b) { return modint(1LL * a.n * b.n % mod); ... | 4 |
using namespace std;
#include <iostream>
#include <string>
#include <set>
#include <functional>
#include <vector>
#include <algorithm>
#include <stdio.h>
int main()
{
int n;
while(cin>>n&&n){
while(n--){
int a,b,c,d,e,f,g,h;
cin>>a>>b>>c>>d>>e>>f>>g>>h;
printf("%d %d %d %d\n",a*e-b*f-c*g-d*h,a*f+b*e+c*h-d*... | 0 |
#include <iostream>
int main(){
int N,H,W;
std::cin>> N >> H >> W;
std::cout << (N-H+1)*(N-W+1);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1507;
int n;
long long a[maxn];
struct node {
int l, r;
long long sum;
node() {}
node(int a, int b, long long c) { l = a, r = b, sum = c; }
bool operator<(const node &a) const { return r < a.r; }
};
map<long long, vector<node> > mp, ans;
map<long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a[3];
bool ok(int last) {
if (a[0] == a[1]) return false;
if (a[0] == a[2]) return false;
if (a[1] == a[2]) return false;
int mx = 0;
for (int i = 0; i < 3; i++) {
if (a[i] > a[mx]) mx = i;
}
if (mx != last) return true;
ll v1 = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5;
const int INF = 1e9;
int head[maxn + 5], sz[maxn + 5], dis[maxn + 5], cnt[maxn + 5], tp[5];
bool vis[maxn + 5];
long long dp1[maxn + 5], dp2[maxn + 5], ans[5];
int root, mn, tot;
int n, k, u, v;
long long sum;
int num = 0;
struct edge {
int to, _next... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, m, r;
cin >> n >> m >> r;
int si = 1001, bi = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
si = min(x, si);
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
bi = max(x, bi);
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
void IO() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
IO();
long long int n;
cin >> n;
vector<long long int> arr(n);
for (__typeof(n) i = (0) - ((0) > (n)); i ... | 4 |
#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;
string s;
cin >> s;
bool found = false;
for (int i = 0; i < n and !found; i++) {
for (int j = i + 1; j < n and !... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
map<int,int> mp;
vector<long long int>count(n+1,0);
for(int i=0;i<m;i++){
int a;
cin >> a;
mp[a]=1;
}
count[0]=1;
count[1]=mp[1]==0;
for(int i=2;i<=n;i++){
if(mp[i]==1)count[i]=0;
else count[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, double> dp[2000][2000];
struct XD {
int scs, scl, ts, tl;
double prf;
long long prll;
bool operator<(const XD& b) const {
if (prll == 1000000) return 0;
if (b.prll == 1000000) return 1;
return prll * tl * (1000000 - b.prll) < b.prll * b.t... | 4 |
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPP(i,j,n) for(int i=(j);i<(int)(n);i++)
using namespace std;
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-5, pi = acos(-1.0);
ld dot(Point a, Point b){return real(co... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 405;
const int oo = 1e9;
int n, k;
int dp[N][N], pr[N], eg[N][N];
bool kt[N];
map<pair<int, int>, int> mask[N];
vector<int> vi[N];
vector<pair<int, int> > egtmp;
void solve(int pre, int u) {
pr[u] = pre;
dp[u][1] = 0;
for (int v : vi[u])
if (v != pre... | 4 |
#include <bits/stdc++.h>
using namespace std;
int arr[30];
int calen[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30,
31, 30, 31, 31, 30, 31, 30, 31, 31, 28, 31, 30, 31, 30, 31, 31,
30, 31, 30, 31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 3... | 2 |
#include<bits/stdc++.h>
using namespace std;
int a[30],b[30];
int ans;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
cin>>b[i];
for(int i=1;i<=n;i++){
if(b[i]<a[i])
ans+=(a[i]-b[i]);
}
cout<<ans<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
const long long int null = 3000;
long long int si[10000], sj[10000], m[2050][2050], s[5000][5000], max[2][2],
maxij[2][2][2], n;
long long int maxst(long long int a, long long int b) {
if (a > b)
return a;
else
return b;
}
void sol() {
long long int i, j, x;
for (i = 0; i < ... | 3 |
#include<stdio.h>
#include<iostream>
#include<stack>
#include<algorithm>
#define MAX 1400
using namespace std;
struct Rectangle { int height; int pos; };
int getLargestRectangle(int size, int buffer[]) {
stack<Rectangle> S;
int maxv = 0;
buffer[size] = 0;
for ( int i = 0; i <= size; i++ ) {
Rectangle re... | 0 |
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#inc... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s = "";
cin >> n;
while (true) {
for (char ch = 'a'; ch <= 'a' + 3; ch++) {
s += ch;
if (s.length() == n) {
cout << s << endl;
return 0;
}
}
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
long long int a[100001];
int N, M, c, v, x, j, add;
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = 0; i < M; i++) {
cin >> c;
switch (c) {
case 1:
cin >> v >> x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int T, n, k;
long long ans;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &k);
ans = 0;
int now = ceil((double)n / 2);
for (int i = 1, x; i <= n * k; i++) {
scanf("%d", &x);
if (i <= (now - 1) * k) continue;
if ((i - 1 -... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, inf = 1e18, mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n, k1, k2;
cin >> n >> k1 >> k2;
bool f = false;
while (k1--) {
l... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int m, c[50];
long long... | 4 |
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);
using namespace std;
namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(cons... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long mod = 1000000007;
long long r(pair<int, int> a) {
long long x = a.first;
long long y = a.second;
return x * x + y * y;
}
pair<int, int> operator+(pair<int, ... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
int gi() {
int x=0,o=1;char ch=getchar();
while(!isdigit(ch)&&ch!='-') ch=getchar();
if(ch=='-') o=-1,ch=getchar();
while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x*o;
}
struct line {
int k;ll b;
line(int k=0,ll b=0):... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn], b[maxn], c[maxn], lson[maxn], rson[maxn], stk[maxn];
int vis[maxn];
int dep[maxn];
int rt, n;
void build() {
int top = 0;
for (int i = 1; i <= n; i++) {
lson[i] = rson[i] = vis[i] = 0;
}
for (int i = 1; i <= n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long w = 1, q = 0;
char ch = ' ';
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (ch >= '0' && ch <= '9') q = q * 10 + ch - '0', ch = getchar();
return w * q;
}
const int maxn = 9 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<long long int, string> sn;
pair<long long int, pair<long long int, string> > rsn;
pair<long long int, pair<string, string> > rn1n2;
pair<string, string> n1n2;
set<pair<long long int, pair<string, string> > > ans;
set<pair<long long int, pair<lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, x, y;
cin >> a >> b >> x >> y;
x++;
y++;
int a1 = (x - 1) * b;
int a2 = (a - x) * b;
int a3 = (y - 1) * a;
int a4 = (b - y) * a;
cout... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long x, y = 1e18;
vector<long long> v;
map<long long, long long> m;
bool h = false;
for (lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const string nl = "\n";
static struct FastInput {
static constexpr long long BUF_SIZE = 1 << 20;
char buf[BUF_SIZE];
size_t chars_read = 0;
size_t buf_pos = 0;
FILE* in = stdin;
char cur = 0;
inline ch... | 4 |
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, b[100005], g[100005], bmx, gmi, sum[100005], sumg;
int main() {
scanf("%lld%lld", &n, &m);
bmx = 0, gmi = 100000000;
for (int i = 1; i <= n; i++) {
scanf("%lld", &b[i]);
bmx = max(bmx, b[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%lld... | 3 |
#include <bits/stdc++.h>
using namespace std;
int const N = 5e5, oo = 1e9;
int mod = oo + 7;
double const eps = 5e-6;
int n, s, an, aa[N];
map<int, int> cnt;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
cin >> aa[i];
if (i == s - 1) {
if (aa[i]) an++;
cnt[0]++;
} else
cnt[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long res_even[n / 2];
long long res_odd[n / 2];
int quotient = n / 2;
if (quotient % 2 != 0) {
cout << "NO" << endl;
continue;
}
cout << "YES" << endl;
... | 2 |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int h, w;
while (cin >> h >> w, h) {
vector<vector<string>> map(h, vector<string>(w));
for (auto &seq : map) {
for (auto &v : seq) {
char c;
cin >> c;
v = c;
}
}
int cx =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long maxs = 1e6 + 321;
long long mpow(long long a, long long b, long long p) {
if (b == 0) return 1;
long long t = mpow(a * a % p, b / 2, p);
if (b % 2) t = t * a % p;
return t;
}
long long fact[maxs], invf[maxs];
int main() {
ios::sync_with_stdio(false... | 6 |
#include <bits/stdc++.h>
using namespace std;
char a[] = "23456789TJQKA";
char b[] = "SDHC";
int Get() {
char s[3];
scanf("%s", s);
int i = 0;
while (a[i] != s[0]) ++i;
int j = 0;
while (b[j] != s[1]) ++j;
return i * 4 + j;
}
int Good(int first, int second) {
return (first / 4 == second / 4) || (first %... | 2 |
//56
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<29)
int main(){
for(int n,m;cin>>n>>m,n|m;){
int cm[101][101];
int tm[101][101];
fill_n(cm[0],101*101,INF);
fill_n(tm[0],101*101,INF);
for(int i=1;i<=100;i++){
cm[i][i]=tm[i][i]=0;
}
for(int i=0;i<n;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool used[200001];
int diff[200001];
int n;
vector<int> picked;
void bf() {
if (picked.size() == n) {
for (auto it : picked) cout << it << ' ';
exit(0);
}
int find = picked.back() + diff[picked.size() - 1];
if (find <= 0 || find > n || used[find]) {
retu... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[205], b[205];
long long dp[205][10005];
long long n, m;
long long ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
long long t;
cin >> t;
wh... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, i;
cin >> n;
vector<long long int> a(n);
for (i = 0; i < (n); i++) cin >> a[i];
long long int l, r;
l = 0;
r = n - 1;
long long int cnt1 = 0;
long long int cnt2 = 0;
long long int f = 0;
while (l <= r) {
if (a[l] > a... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct work {
int l, r, t, id;
};
int inf = (int)2e9;
struct node {
int to_min, to_sub;
node() { to_min = to_sub = 0; }
};
struct MTree {
vector<node> tree;
int st, d;
MTree(int n) {
st = 1;
d = 0;
while (st < n) {
st *= 2;
d++;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m >> a >> b;
cout << min(n * a, (n / m * b + min((n % m) * a, b)));
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6 + 9;
const int Maxv = 3015;
pair<int, int> Que[Maxn * 10];
int bg, ed;
bool arr_mark[Maxv][Maxv];
int arr_num[Maxv][Maxv];
inline int num(pair<int, int> p) {
int x = p.first, y = p.second;
if (abs(x) >= Maxv / 2 - 1 || abs(y) >= Maxv / 2 - 1) return... | 2 |
#include <iostream>
#include <math.h>
#include <string.h>
#include <stdio.h>
using namespace std;
int n ,m;
int main()
{
int cas;
cin >> cas;
for(int i = 0 ;i < cas;i++) {
scanf("%d%d",&m,&n);
if(m *m + n * n <= 1) {
puts("C");
continue;
}
int div =... | 0 |
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
int main(){
ll n, k; cin >> n >> k;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ll ans1=0;
rep(j,n)rep(i,j)
if(a[i]>a[j]) ans1++;
ll ans2=0;
rep(i,n)rep(j,n)
if(a[i]>a... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
long long n;
const long long maxn = 2e5 + 50;
vector<long long> r[maxn], dp(maxn), second(maxn);
void dfs(long long v, long long p = -1) {
dp[v] = 0;
second[v] = 1;
for (auto &u : r[v]) {
if (u == p) continue;
dfs(u, v);
second[v] += ... | 5 |
#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>
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d = 0, e = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i > 0) {
e += a[i - 1] - a[i];
if (e < 0) {
d -= e;
e = 0;
}
} else {
d += a[0];
}
}
cout << d;
return ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
char s[MAXN];
int len;
long long a[MAXN];
int n;
long long pre1[MAXN], pre2[MAXN];
long long cnt[5][5], ans[5];
int main() {
pre1[0] = pre2[0] = 0;
for (int i = 1; i <= 50000; i++) {
pre1[i] = pre1[i - 1];
pre2[i] = pre2[i - 1];
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 100;
map<int, int> m;
map<int, int> m_;
int d[MAXN];
vector<int> N[MAXN];
bool mark[MAXN];
void dfs(int v) {
mark[v] = 1;
cout << m_[v] << " ";
for (int i = 0; i < N[v].size(); i++)
if (mark[N[v][i]] == 0) dfs(N[v][i]);
}
int main() {
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct seg {
public:
long long x, y, x1, x2, y1, y2;
};
bool pl(seg a, seg b) {
if (a.y <= b.y2 && a.y >= b.y1 && b.x <= a.x2 && b.x >= a.x1)
return true;
else
return false;
}
long long f(seg a, seg b) {
long long x = b.x;
long long y = a.y;
long long a... | 4 |
#include <bits/stdc++.h>
const int maxn = 1e5 + 100, mod = 1e9 + 7;
using namespace std;
long long fib[51];
bool swap(int* arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
int binarySearch(int p1, int p2, long long target) {
if (p1 > p2) {
return p2;
}
int pivot = (p1 + p2) / 2;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int MinDist(int n, int k, const string& s) {
int first_cow_pos = 0;
while (first_cow_pos < n && s[first_cow_pos] == '1') {
++first_cow_pos;
}
int last_cow_pos = first_cow_pos;
int rooms = 1;
while (rooms < k + 1) {
++last_cow_pos;
if (s[last_cow_pos]... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a, b, c; cin >> a >> b >> c;
for (int i = 1; i <= (int)1e7; i++){
if (a & 1 || b & 1 || c & 1){
cout << i-1 << "\n";
return 0;
}
int aa = a/2, bb = b/2, cc = c/2;
a = bb+cc;
b = cc+aa;
c = aa+bb;
}
cout << "-1\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
int a, b, x, y;
scanf("%d%d%d%d", &a, &b, &x, &y);
int k = gcd(x, y);
x /= k;
y /= k;
k = min(a / x, b / y);
printf("%d %d\n", k * x, k * y);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod(long long a, long long n) {
if (n < 0) n *= -1;
if (a >= 0) return a % n;
a = (-a) % n;
if (a < 0) a += n;
return a;
}
long long gcd(long long a, long long b) {
if (a < 0) a *= -1;
if (b < 0) b *= -1;
if (a < b) return gcd(b, a);
if (a % b ==... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename __T>
inline void read(__T &x) {
x = 0;
int f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
pair<int, int> mp(int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
string s, t;
cin >> s >> t;
long long sa = 0, sb = 0, ta = 0, tb = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == 'a')
sa++;
else
... | 3 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
m.clear();
int n;
cin >> n;
int a[n + 1], mx = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
... | 3 |
#include <bits/stdc++.h>
int main() {
int a, b, temp;
scanf("%d %d", &a, &b);
if (a > b) {
temp = a;
a = b;
b = temp;
}
printf("%d %d\n", a, (b - a) / 2);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long l[10003], s[10003];
int main() {
long i, j, k, m, n;
char c[10003];
cin >> n >> m;
for (i = 1; i <= n; ++i) {
cin >> (c + 1);
l[0] = 0;
for (j = 1; j <= m; ++j)
if (c[j] == '1') l[++l[0]] = j;
if (l[0] == 0) {
cout << -1 << endl;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, y = 0;
cin >> a >> b;
int arr1[a], arr2[a];
for (int i = 0; i < a; i++) {
cin >> arr1[i];
}
for (int i = 0; i < a; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int mat[105][105];
int col[105];
int row[105];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> mat[i][j];
}
}
bool flag = 0;
while (!flag) {
fl... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
int H[100050], parent[100050], sz[100050], L[100050 << 1], E[100050 << 1],
M[100050][20], SEG[(100050 << 3) + 15];
int n, timer;
int dfs(int node, int depth, int perr) {
sz[node] = 1;
H[node] = timer;
E[timer] = node;
L[timer++] = depth... | 5 |
#include <bits/stdc++.h>
using namespace std;
char st[10000];
int len, f[30];
int main() {
scanf("%s", st);
len = strlen(st);
memset(f, 0, sizeof(f));
int o = 0;
for (int i = 0; i < len; i++)
if (st[i] == '*') f[++o] = i;
long long ans = 0;
long long fac = 1;
long long sum;
for (int i = 0; i < len... | 5 |
#include<iostream>
#include<vector>
using namespace std;
long long n,k;
vector<long long> a;
bool C(long long x){
long long num=0;
for(int i=0;i<n;++i){
num+=(a[i]+x-1)/x-1;
}
return num<=k;
}
int main(){
cin>>n>>k;
a.resize(n);
for(long long i=0;i<n;++i) cin>>a[i];
long long... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > a;
vector<pair<int, int> > res;
int pos[111111];
int rpos[111111];
vector<bool> c;
int n;
bool good(int x) {
while (x != 0) {
int d = x % 10;
if (d != 4 && d != 7) return false;
x /= 10;
}
return true;
}
void fix(int from, int to) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100, maxc = 115, inf = 1e9 + 10;
long long t, n, f[100], dp1[100], dp2[100];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
f[0] = f[1] = 1;
for (int i = 2; f[i - 1] < (long long)1e18; i++) f[i] = f[i - 1] + f[i - 2];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 330;
const int mod = 1e9 + 7;
string s[N];
int st[N], en[N];
int n, m;
int len[N];
string fi[N], se[N];
bitset<20000> ok[N][14];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> s[i];
len[i] = s[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)(1e9) + 7;
const int SIZE = 2020;
int d, n;
int a[SIZE];
vector<int> path[SIZE];
long long f[SIZE];
bool vis[SIZE];
void dfs(int x, int root) {
f[x] = 1;
for (int i = 0; i < path[x].size(); i++) {
int son = path[x][i];
if (vis[son] || !(a[so... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int HASH = 1000000007;
map<int, int> node, sum;
int h, q;
double dfs(int root, int v) {
if (sum[root] <= v) {
return v;
}
return (dfs(root << 1, max(v, node[root] + sum[root << 1 | 1])) +
dfs(root << 1 | 1, max(v, node[root] + s... | 4 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int a[303030];
void jud(int l,int r)
{
int now1=0,now2=0;
for(int i=l;i<=r;i+=2)
{
if(i<a[i])
{
if(a[i]>now1)
now1=a[i];
else
{
printf("No");
exit(0);
}
}
else
{
if(a... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, sum[100009], vis[100009], m, n, d, k, mn, mx, ans = 1;
vector<long long> v[100009];
map<long long, long long> mp;
char par[1000009];
int main() {
cin >> n;
mp[n]++;
n++;
while (1) {
if (n % 10 == 0) {
n /= 10;
} else {
if (mp[n] >... | 1 |
#include <bits/stdc++.h>
int main() {
int n, bars[1000], i, j;
int total, lgst = 1, lcheck;
while (scanf("%d", &n) != EOF) {
total = n;
lgst = 1;
for (i = 0; i < n; i++) {
scanf("%d", &bars[i]);
}
lcheck = 1;
for (i = 0; i < n; i++) {
lgst = 1;
for (j = i + 1; j < n; j++)... | 1 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 3 |
#include <bits/stdc++.h>
using namespace std;
int x, ma = 0, mi = 101, n, m, mm = 101;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &x), ma = max(ma, x), mi = min(mi, x);
ma = max(ma, mi * 2);
for (int i = 1; i <= m; i++) scanf("%d", &x), mm = min(mm, x);
if (mm > ma)
p... | 1 |
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
class LowerEnvelope{ typedef long long LL; int s, t; vector<LL> deq_a; vector<LL> deq_b; inline bool check(LL a1, LL b1, LL a2, LL b2, LL a3, LL b3) const { return (a2 - a1) * (b3 - b2) >= (b2 - b1) * (a... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long tree[4 * 1000000];
void upd(int i, int s, int e, int s1, int e1, long long v) {
if (s > e1 || s1 > e) return;
if (s >= s1 && e <= e1) {
tree[i] = (tree[i] + v % mod) % mod;
return;
}
upd((i * 2), s, ((s + e) / 2), ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, l, r, i, j, x, ans = -1;
void work(long long x) {
if (x > n && x <= 2 * n) ans = max(ans, x - n);
}
int main() {
cin >> n >> l >> r >> m;
r = (r - l + 1 + n) % n;
if (m < r) {
puts("-1");
return 0;
}
for (i = n; i <= m && i <= 2 * n; i = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a1[200000], a2[200000];
int s1[200000], s2[200000], d1[200000], d2[200000];
long long rot(long long q, long long w, long long e, long long r, long long t,
long long y) {
return (e - q) * (y - w) - (t - q) * (r - w);
}
int cmp(long long c1, long long c2, ... | 2 |
#include <bits/stdc++.h>
int main() {
int n, m, i, t, x, y;
scanf("%d %d", &n, &m);
if ((m == 3) && (n > 4)) {
printf("-1\n");
return 0;
}
x = 0;
y = 0;
t = 0;
for (i = 0; i < m; i++) {
printf("%d %d\n", x, y);
x += 2;
y += t;
t += 5;
}
if (n > m) printf("1 1\n");
if (n == ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000010, MOD = 1e9 + 7;
int a[200020];
int b[N];
bool have[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", a + i);
sort(a, a + n);
n = unique(a, a + n) - a;
int mx = a[n - 1];
mx <<= 1;
int ans = 0;
int i = a[0] == 1... | 2 |
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d%d", &a, &b);
if (a == b) {
printf("%d 0\n", a);
}
if (a > b) {
printf("%d %d\n", b, (a - b) / 2);
}
if (a < b) {
printf("%d %d\n", a, (b - a) / 2);
}
return 0;
}
| 1 |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pa... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.