solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
double start_moment = 0;
double get_runtime() { return 1.0 * clock() / CLOCKS_PER_SEC; }
void reset_timer() { start_moment = get_runtime(); }
double timer_time() { return get_runtime() - start_moment; }
void runtime() { cout << fixed << setprecision(5) << get_runtime() << '... | 5 |
#include <bits/stdc++.h>
using namespace std;
int d[300005], target[600005], pre[600005], last[300005], tot = 1, ans[300005];
bool visited[300005];
void add(int x, int y) {
target[++tot] = y;
pre[tot] = last[x];
last[x] = tot;
}
void dfs(int x) {
visited[x] = 1;
for (int i = last[x]; i; i = pre[i]) {
int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[1010000], b[1010000], tms[1010000], C[1010000];
const long long mod = 1000000007;
long long qpow(long long x, long long y, const long long& k) {
long long t = 1;
while (y) {
if (y & 1) {
t = t * x % k;
}
x = x * x % k;
y >>= 1;
}
re... | 2 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s,v;
cin>>s>>v;
int ans=INT_MAX;
for(int i=0;i<=s.size()-v.size();i++){
int cnt=0;
for(int j=i;j<i+v.size();j++){
if(v[j-i]!=s[j])
cnt++;
}
ans=min(ans,cnt);
}
cout<<ans<<endl;
return 0;
} | 0 |
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
using namespace std;
int main(){
int n;
cin>>n;
long long int x;
long long int s=0;
priority_queue<long long int,vector<long long int>,greater<long long int>>q;
for(int i=0;i<n;i++){
cin>>x;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000003;
const long long INF = mod * mod;
const double eps = 1e-8;
const double pi = acos(-1.0);
struct query {
int l, r;
long long d;
};
void solve() {
int n;
cin >> n;
vector<long long> s(n), t(n);
for (int i = 0; i < n; i++) {
cin >>... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k;
cin >> n >> k;
vector<int> lig(n);
for(int i=0; i<n; ++i) cin >> lig[i];
for(int i=0; i<k; ++i){
vector<int> nlig(n+1,0);
for(int j=0; j<n; ++j){
int plus = max(0,j-lig[j]);
int mai = min(n,j+lig[j]+1);
++nlig[plus]... | 0 |
#include <bits/stdc++.h>
using namespace std;
int const mxsz = 509;
long long w[mxsz][mxsz];
bool ver[mxsz];
int main() {
vector<int> er;
vector<long long> res;
int n;
scanf("%d", &n);
er.resize(n);
for (int i = 0; i < n; ++i) {
int x;
for (int j = 0; j < n; ++j) {
scanf("%d", &x);
w[i][... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long int infi = 1e18 + 5;
long long int n;
long long int sa[N], ea[N], sb[N], eb[N];
bool func() {
set<long long int> left, right;
vector<pair<long long int, long long int> > v;
for (long long int i = 1; i <= n; i++) {
v.push_back... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
int p = 0, q = 0;
int lp = 0, lq = 0;
int ls, lt, ks, kt;
vector<int> a, b;
void sw(int a0, int b0) {
a.push_back(a0 + lp + 1);
b.push_back(b0 + lq + 1);
swap(lp, lq);
lp += b0 - a0;
lq += a0 - b0;
}
void init() {
ls = s.length(), lt = t.length();
... | 6 |
#include <bits/stdc++.h>
using namespace std;
long int b[300013];
void Ok() {
long int a, c, h, t, i = 0, j = 0, k, l, m, n;
long int ans_1, ans_2, ans_3, cnt = 0, Max, Min, flag = 0, temp, sum = 0;
double aa, bb, cc, dd, ee, ff, gg;
char aaa[113][113], bbb[113], ccc[113], ddd;
string spc, in;
cin >> t;
w... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long A[100005], P[100005], N, S;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
S += A[i];
}
sort(A, A + N);
for (int i = 1; i < N; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> raices;
void raiz(long long n) {
for (int i = 2; i < n; i++) {
raices.push_back(i * i);
}
}
long long bun(int n) {
if (n == 0) {
return 0;
}
return (2 * bun(n - 1) + 2);
}
long long paty(int n) {
if (n == 0) {
return 1;
}
return (2 * ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int eps = 1e-10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 100005;
int n;
long long a[maxn];
long long sum;
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", a + i);
a[0] = 0;
... | 5 |
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
cout<<(n*n*n)<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int d[21][21], a[21], b;
void DFS() {
int x = 0, y = 0;
for (int i = 1; i < b; i++) {
if (a[i - 1] < a[i] && a[i] > a[i + 1])
x++;
else if (a[i - 1] > a[i] && a[i] < a[i + 1])
y++;
}
if (x - 1 == y) d[b][x]++;
if (b == 19) return;
if (a[b] !=... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
long long n, m;
long long a[N], ans[N];
set<long long> active;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
active.insert(i);
}
cin >> m;... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> record;
vector<int> dist;
vector<int> deg;
vector<vector<int>> edges;
int idx;
void dfs(int v, int p, int dep){
dist.push_back(dep);
int r = record[idx];
if(0 <= p){
r--;
edges.push_back({p});
deg[p]--;
edges[p].push... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2 * 1e6 + 10;
long long INF = 1e9 + 10;
long long MOD = 998244353;
int n;
pair<int, int> a[MAXN];
pair<int, int> b[MAXN];
int func(int x, int cnt) {
int res = 0;
for (int pos = 0; pos < cnt; pos++) res += (1 << pos) * (int)((x >> pos) & 1);
return res... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[500010];
int A[500010], n;
struct node {
long long sum, suml, sumr, sum_;
int L, R;
friend node operator+(const node &a, const node &b) {
node c;
int t = a.R * 10 + b.L;
int t1 = (t <= 18 && t > 9 ? 10 - abs(t - 9) : 0);
c.sum = (a.sum * b.sum +... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define EPS 1e-9
#define M 256
#define INF 1e9
int main(){
int N;
while(cin >> N, N > 0){
int I[N+1],R[N+1],O[N+1];
for(int i = 0 ; i < N ; i++){
cin >> I[i];
}
int S,A,C;
double ans = INF;
for(int s = 0 ; s <= 15 ; s++){
for(int a... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
template <class T>
void printImpl(const vector<T>& coll) {
copy(coll.begin(), coll.end(), ostream_iterator<T>(cout, " "));
cout << endl;
}
template <class T, int N>
void printImpl(T (&coll)[N]) {
copy(coll, coll + N, ostream_iterator<... | 1 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)
int n;
char s[55][25];
ll c[55];
bool ispal(char *s, int l, int r) {
while (l < r) {
if (s[l] != s[r... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout.precision(10);
cout << fixed;
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; ++i) {
cin >> p[i];
--p[i];
}
vector<vector<int> > a(N);
for (int i = 0; i < N; ++i) {
int k;
cin >> k;
for (int j = 0; j < k; ++j... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,x,y,ans;
cin>>a>>b>>c>>x>>y;
ans=max(x,y)*2*c;
ans=min(ans,min(x,y)*2*c+((x>y)?(x-y)*a:(y-x)*b));
ans=min(ans,a*x+b*y);
cout<<ans;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;
ll n;
vector<ll>c;
vector<ll>to[10005];
vector<ll>ans;
ll x=0;
void dfs(ll v, ll p = -1){
ans[v]=c[x];
x++;
for(ll i=0; i<to[v].size(); i++){
ll u = to[v][i];
if(u==p) continue;
dfs(u,v);
}
}
int main(){
cin >>... | 0 |
#include<iostream>
using namespace std;
int main(){
int n,m;
int a,b,c;
int i,j,k;
int s=0;
while(cin>>n){
if(!n)break;
b=0,c=1e5,s=0;
for(i=0;i<n;i++){
cin>>a;
if(b<a)b=a;
if(a<c)c=a;
s+=a;
}
s-=b+c,n-=2;
s/=n;
cout<<s<<endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
struct Mat {
int ma[MAX][MAX];
void clear() { memset(ma, 0, sizeof(ma)); }
} res[MAX];
int pow4[] = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
int mxsize;
int FourBit(int val) {
for (int i = 0;; i++)
if (pow4[i] > val) return i - 1;
}
void... | 2 |
#include <iostream>
#include <algorithm>
using namespace std;
int n, m[2], b[2][28], in, T = 0;
char d[2][5][5][5];
int main(){
while(cin >> n && n){
if(T) cout << endl;
for(int k=0;k<5;k++) for(int j=0;j<5;j++) for(int i=0;i<5;i++) cin >> d[0][i][j][k];
fill(b[0], b[2], 0);
for(int i=0;i<2;i++){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, q, poz[100000 + 10];
long long ans1, ans2;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
poz[x] = i;
}
cin >> q;
while (q--) {
int x;
cin >> x;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, x, maxx, b[1000000], a[1000000], ans, kol, ii;
int t = 0;
bool ok;
int main() {
cin >> n >> k >> x;
for (int i = 0; i < n; i++) cin >> a[i];
maxx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) b[j] = a[j];
b[i] = x;
k = i;... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
ll mi(ll a, ll b, ll p) {
ll r = 1;
while (b) {
if (1 & b) r = r * a % p;
a = a * a % p;
b >>= 1;
}
return r;
}
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
ll d = ex... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
A convert(B x) {
stringstream ss;
ss << x;
A ret;
ss >> ret;
return ret;
}
const int oo = ~0u >> 2;
const double eps = 1e-10, pi = acos(-1);
const int ROW = 7, COL = 8, mp = 10, mc = 4 - 1, MAX_PTS = mp * 2 + 10,
MAX_EDGES = (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin >> a >> b;
if(a>b)swap(a,b);
for(int i=0;i<b;i++)cout << a;
cout << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
int main() {
int T, n;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
int ans = 0x3f3f3f3f, a, b;
for (int x = 1, m; x * x <= n; ++x)
if (m % x == 0) {
m = x;
if (m && (n - m) && m * (n / m - 1) < ans) {
ans = m * (n / m - 1);
a = m;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int pr[MAX];
int ht[MAX];
int tin[MAX];
int tout[MAX];
int rev[MAX];
vector<int> adj[MAX];
vector<int> val[MAX * 4];
vector<int> vech[MAX * 4];
int tim;
void dfs(int s, int p) {
tin[s] = (++tim);
rev[tim] = s;
for (int i = 0; i < adj[s].size()... | 6 |
#include <bits/stdc++.h>
using namespace std;
int Pm[2002][2002];
int main() {
int n;
cin >> n;
vector<pair<int, int>> p(n);
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
Pm[x + 1000][y + 1000] = 1;
p[i] = {x, y};
}
int ans = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int const inf = 1e18;
long long int const maxn = 1e6 + 5;
long long int const mod = 1e9 + 7;
long long int n, m;
bool isValid(long long int u, long long int v) {
return u >= 0 && u < n && v >= 0 && v < m;
}
int main() {
ios_base::sync_with_stdio(false);
cin.... | 2 |
#include <bits/stdc++.h>
using namespace std;
int num[1001] = {0};
int main() {
int n, sum = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> num[i];
sort(num, num + n);
sum = num[n - 1] - num[0] + 1 - n;
cout << sum << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int b[100005];
int a[100005];
int help[100005];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
if (n <= 2) {
printf("0\n");
return 0;
}
for (int i = 0; i < n - 1; i++) a[i] = b[i + 1] - b[i];
int maxvalue = -0x3f3f3f... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long max(long long a, long long b) {
if (b <= a)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (b <= a)
return b;
else
return a;
}
long long fact(long long a) {
long long f = 1;
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, k;
cin >> n >> k;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
long long int remain = 0;
long long int ans = 0, prev;
for (lon... | 4 |
#include<bits/stdc++.h>
#define maxn 600005
#define rep(i,j,k) for(int i=(j),LIM=(k);i<=LIM;i++)
#define per(i,j,k) for(int i=(j),LIM=(k);i>=LIM;i--)
#define mod 924844033
using namespace std;
int n,sz[maxn],A[maxn],B[maxn];
vector<int>G[maxn];
void dfs(int u,int ff){
sz[u] = 1;
int v;
rep(i,0,G[u].size()-1) if((v... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, v, l, r, i;
cin >> n >> l >> r;
stack<int> s;
vector<int> a(n);
vector<int> c(n, INT_MAX);
vector<int> d(n, INT_MIN);
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
while (!s.empty() && a[s.top()] >... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[2000000];
void solve() {
long long n;
scanf("%d", &n);
long long cnt = (1 << (n + 1)) - 1;
for (long long i = 2; i <= cnt; i++) {
scanf("%d", a + i);
}
long long ans = 0;
for (long long t = (1 << n) - 1; t >= 1; t--) {
long long x = a[t * 2... | 2 |
#include<set>
#include<iostream>
using namespace std;
int main() {
int T;
cin >> T;
set<int> s;
while (T--) {
int a;
cin >> a;
if (a==0) {int t; cin >> t;s.insert(t);
cout << s.size() << endl;
}
else if (a==1) {
int t;
cin >> t;... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int ans=0;
for(int i=1;i<n-1;i++)
{
if((a[i-1]<a[i]&&a[i+1]>a[i])||\
a[i-1]>a[i]&&a[i+1]<a[i])
{
ans++;
}
}
cout<<ans<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
while (scanf("%lld", &n) == 1) {
long long res;
if (n == 1)
res = 1;
else if (n == 2)
res = 2;
else
res = n * (n - 1) * (n - 2);
if (n % 6 == 0)
res = max(res / 2, (n - 1) * (n - 2) * (n - 3));
el... | 1 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
int n, m, k;
int comp_num = 0;
char v[1005][1005];
int matrix[1005][1005];
int vis[1005][1005];
int ans[100005];
bool ok(int x, int y) { return (x >= 0 && x < n && y >= 0 && y < m); }
int dfs(int x, int y) {
int a, b;
... | 4 |
#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printA... | 0 |
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;
typedef pair<P, P>PP;
ll dy[5] = {0, 1, 0, -1, 0};
ll dx[5] = {1, 0, -1, 0, 0};
ll change[5][5] = {
{0, 1, 2, 3, 4},
{1, 2, 3, 0, 4},
{2, 3, 0, 1, 4},
{3, 0, 1, 2, 4},
{4, 4, 4, 4, 4}
};
ll mp[33][33];
ll... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
while (*s != ',') cerr << *s++;
cerr << " = " << x << ',';
_DBG(s + 1, a...);
}
int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
string s;
cin >> s;
for (int i = 1; i <= t; i++) {
if (t % i == 0) {
reverse(s.begin(), s.begin() + i);
}
}
cout << s;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
double p[10000009], dp[10000009], ans[30];
int main() {
int n, k;
memset(dp, 0, sizeof(dp));
memset(ans, 0, sizeof(ans));
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%lf", &p[i]);
dp[0] = 1;
for (int i = 0; i < (1 << n); i++) {
double t = 0, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ar[90] = {0, 1, 1, 2};
long long x, y, ans, z;
long long fn() {
if (x < 0 && y <= 0) {
if (z > y) return -1;
return 0;
}
if (z <= y) return 0;
long long cnt = 0, sum = 0, s = 0, p = 1, q = 2, i1 = 0, i2 = 1;
if (x < 0) cnt = (abs(x) / y), x = x +... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'H' || s[i] == 'Q' || s[i] == '9') {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
}
| 1 |
#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--) {
long long l, r;
cin >> l >> r;
long long ans = (r / 2) + 1;
if (ans < l) {
ans = l;
}
cout << (long long)r % ans << endl;
}
return 0;... | 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... | 1 |
#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--) {
long long int n, s;
cin >> n >> s;
vector<int> v;
long long int x = n, sm = 0;
while (x) {
v.push_back(x % 10);
sm += (x % 10);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int main() {
double count = 0.00;
cin >> s1;
cin >> s2;
int desired_position = 0;
for (auto k : s1) {
if (k == '+')
desired_position++;
else
desired_position--;
}
int fixed_postion = 0, question_marks = 0;
for (auto k : s2)... | 2 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> P;
bool prime[1000001];
int n,m;
int fie[1200][1200];
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
int numx[1000001],numy[1000001];
int dp[1201][1201];
void seive(){
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S,T;
cin >> S >>T;
map<char,char> ma,ima;
bool flag = true;
for(int i = 0;i<S.size();i++){
char s = S[i];
char t = T[i];
if(ima.count(t)){
if(ima[t] != s) flag = false;
}
if(ma.count(s)){
if(ma[s] != t) flag =... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, c;
bool ch(long long m) {
if (m == 0) return c == 1;
double all = 1 + (m * (m + 1) / 2) * 4;
double add = m - x + 1;
if (add > 0) {
add--;
all -= (add * (add + 1) / 2) * 2 + add + 1;
}
add = m - y + 1;
if (add > 0) {
add--;
a... | 2 |
#include <bits/stdc++.h>
int main() {
int h1, h2, h3, m1, m2, m3, sum1, sum2;
scanf("%d:%d", &h1, &m1);
sum1 = h1 * 60 + m1;
scanf("%d:%d", &h2, &m2);
sum2 = h2 * 60 + m2;
h3 = (sum1 + sum2) / 2 / 60;
m3 = ((sum1 + sum2) / 2) % 60;
printf("%02d:%02d", h3, m3);
return 0;
}
| 1 |
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int Max_N(131072 + 5);
typedef long long int LL;
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');
}
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int a[200010], v[200010];
bool bb;
int finish;
int dfs(int start, int lab) {
v[start] = lab;
if (v[a[start]] == lab) {
finish = a[start];
return 1;
} else {
if (v[a[start]])
return 0;
else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, i;
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
reverse(a, a + n);
for (i = 0; i < n; i++) cout << a[i] << " ";
cout << endl;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
stack<int> s;
vector<int> v[30004];
int n, m, x, y;
bool vis[30004];
void dfs(int pos) {
vis[pos] = true;
for (int i = 0; i < v[pos].size(); i++)
if (!vis[v[pos][i]]) dfs(v[pos][i]);
s.push(pos);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.t... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10, M = 1 << N;
int n, m, k, q[N], e[N][N];
long long a[N][N], f[M];
long long det(int m) {
long long ans = 1;
for (int i = 0; i < m; i++) {
for (int j = i + 1; j < m; j++) {
while (a[j][i]) {
long long c = a[i][i] / a[j][i];
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1LL << 60;
const int MAXN = 500001, INF = 1e9;
int parent[MAXN], ranking[MAXN];
void UF_precalc(int n) {
for (int v = 1; v <= n; v++) parent[v] = v;
}
int find_set(int v) {
if (v == parent[v]) return v;
return parent[v] = find_set(parent[v]);
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
int allHouses = 0;
int lastHouse = 0;
string street;
void precalc() {
for (int i = 0; i < street.size(); ++i)
if (street[i] == 'H') lastHouse = i;
allHouses = std::count(street.begin(), street.end(), 'H');
}
bool isSolution(int k) {
int theEndIdx = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long getans(long long a, long long b) {
long long x = min(a, b / 2);
a -= x;
b -= 2 * x;
x += min(b, a / 2);
return x;
}
void solve() {
long long a, b;
cin >> a >> b;
if (a < b) swap(a, b);
if (a >= 2 * b) {
cout << min(a / 2, b) << endl;
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[4], i, x, sum = 0;
for (i = 0; i < 4; i++) cin >> a[i];
string s;
cin >> s;
for (i = 0; i < s.length(); i++) {
x = (int)s[i] - 48;
sum += a[x - 1];
}
cout << sum;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
const int maxn = 100001;
int n, k;
double a[maxn], x, y;
inline double dis(double a, double b, double c, double d) {
return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}
inline void work1() {
printf("%.10lf\n", min(dis(a[1], 0, x, y), dis(a[n]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double PI = 2 * acos(0.0);
const int Numnodes = ((int)1e5) + 3;
int main() {
int N, K;
cin >> N >> K;
if (K == 10) {
if (N == 1) return cout << -1 << endl, 0;
for (long long int i = 0; i < (N - 1); i++) cout << 1;
cout << 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T min(T &a, T &b) {
return a < b ? a : b;
}
template <class T>
inline T max(T &a, T &b) {
return a > b ? a : b;
}
template <class T>
void read(T &x) {
char ch;
while ((ch = getchar()) && !isdigit(ch))
;
x = ch - '0';
while ((ch = ge... | 5 |
#include <stdio.h>
int ball[10];
bool can(int n,int left,int right){
bool flag;
if(n==10) return true;
if(ball[n]>right && can(n+1,left ,ball[n])) return true;
if(ball[n]>left && can(n+1,ball[n],right)) return true;
return false;
}
int main(){
int N;
scanf("%d",&N);
for(int i=0;i<N;i++){
for(in... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const int N = 100010;
int main() {
int n;
scanf("%d", &n);
printf("YES\n");
for (; n--;) {
int x1, y1, x2, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int M = 1000000010;
int c = (x1 + M) % 2 * 2 + (y1 + M) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[360361];
long long int k;
bool reach(long long int from, long long int to) {
if (from <= to) return false;
long long int d = from - to;
if (d == 1) return true;
for (long long int i = (long long int)(from - to + 1);
i < ((long long int)(k + 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
signed main(){
string s;cin>>s;
int ans=0;
int n=s.size();
for(int i=0;i<n/2;i++){
if(s[i]!=s[n-i-1])ans++;
}
cout<<ans<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char c;
int res = 0;
while (c = getchar(), !isdigit(c))
;
do {
res = (res << 3) + (res << 1) + (c - '0');
} while (c = getchar(), isdigit(c));
return res;
}
struct point {
double x, y;
int made;
inline point(double _x = 0.0, double _y =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int infint = INT_MAX;
const long long infll = LLONG_MAX;
int arr[600][600];
int score[600];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < n; i++) {
int scr = 0, loc = 0;
for (int... | 2 |
#include <stdio.h>
#include <algorithm>
using namespace std;
int main(){
int i,k,p[3],j[2];
for(i = 0;i < 3;i++) scanf("%d",&p[i]);
for(i = 0;i < 2;i++) scanf("%d",&j[i]);
sort(p,p + 3);
sort(j,j + 2);
printf("%d\n",p[0] + j[0] - 50);
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
float s = 0, d;
cin >> n;
m = n;
while (n--) {
cin >> d;
s = s + d;
}
float f = s / (m);
printf("%lf", f);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T BM(T p, T e, T M) {
long long int ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, x, y;
cin >> a >> b >> x >> y;
int row1 = b * (a - (x + 1));
int row2 = b * (a - (a - (x)));
int rowm = max(row1, row2);
int col1 = a * (b - (y + 1));
int col2 = a * (b - (b - (y)));
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d = 1, i;
cin >> a >> b;
c = min(a, b);
for (i = 1; i <= c; i++) {
d = d * i;
}
cout << d;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long pinf = 1e18 + 4;
const long long ninf = -pinf;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
long long d = 9 + 8 * (n + k);
d = sqrt(d);
long long ans = n - (d - 3) / 2;
cout << ans;
}
| 2 |
// abc161_e2.cc
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, c;
cin >> n >> k >> c;
string s;
cin >> s;
vector<int> ans1, ans2;
for (int i = 0; i < n; i++) {
if (s[i] == 'o' && ans1.size() < k) {
ans1.push_back(i);
i += c;
}
}
for (int i = n - 1; i >= 0; i--) {
if (s[i] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<string> v;
int c[100][100];
int f[300];
int main() {
f['W'] = 1;
f['B'] = -1;
int n, m;
cin >> n >> m;
v = vector<string>(n);
for (int i = 0; i < n; ++i) cin >> v[i];
int ans = 0;
for (int i = n - 1; i >= 0; --i)
for (int j = m - 1; j >= 0; --j)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()
#define mod (int)(998244353)
#define PI 3.14159265358979323846264338327... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res % p;
}
long long int modInverse(long long int n, long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, h;
cin >> s;
h = "hello";
int j = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == h[j]) {
j++;
}
}
if (j == 5)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
int t[40000],u[40000],v[40000];
#define B 200
class UnionFind {
vector<int>par, sz;
public:
UnionFind(int n) {
par = sz = vector<int>(n);
for (int i = 0; i < n; i++) {
par[i] = i;
sz[i] = 1;
}
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int k = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
k = k * 10 + ch - '0';
ch = getchar();
}
return k * f;
}
inline void write(int x... | 5 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> first[301];
inline double ccw(pair<int, int> A, pair<int, int> B, pair<int, int> C) {
return ((double)(B.first - A.first) * (C.second - B.second) -
(B.second - A.second) * (C.first - B.first)) *
0.5;
}
inline double chmax(double &A, doubl... | 2 |
#include <bits/stdc++.h>
long long ans[300009];
int valX[300009], valY[300009];
struct myc {
int x, y, z;
inline bool operator<(const myc &u) const { return y - x > u.y - u.x; }
} v[300009];
int main() {
int n, m;
fscanf(stdin, "%d%d", &n, &m);
long long sumX = 0, sumY = 0;
for (int i = 1; i <= n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int b[5005], c[5005];
double a[5005];
int main() {
while (cin >> n >> m) {
for (int i = 1; i <= n; i++) {
cin >> b[i] >> c[i];
b[i] *= m;
a[i] = b[i] * (1.0) / c[i];
}
sort(a + 1, a + 1 + n);
printf("%.8lf\n", a[1]);
}
retur... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
int f = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
if (ch == '-') {
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s[200005], tot, ta, tb;
vector<pair<int, int> > v[200005];
bool vis[200005];
int ans[200005];
int sum[200005];
void dfs(int a) {
vis[a] = 1;
sum[a] = s[a];
for (int i = 0; i < v[a].size(); i++)
if (vis[v[a][i].first] != 1) {
dfs(v[a][i].first);
... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.