solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[1000010], b[1000010];
const long long inf = 1ll << 60;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; ++i) {
scanf("%d", &b[i]);
}
long long ans = 0, bns = inf;
for (in... | 1 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,b;
cin>>n>>b;
cout<<(n+b)%24<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1061109567;
const int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
string a, b;
int main() {
cin >> a >> b;
int i, j;
for (i = 0, j = 0; i < b.size(); i++) {
if (a[j] == b[i]) {
j++;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303, M = 18;
mt19937 gen(time(NULL));
template <typename T = int>
inline T read() {
T val = 0, sign = 1;
char ch;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') sign = -1;
for (; ch >= '0' && ch <= '9'; ch = getchar()) va... | 4 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const ll mod = 1e9+7;
int main(){
ll h, w, k;
cin >> h >> w >> k;
k--;
vector<vector<ll>> dp(h+1,vector<ll>(w,0));
dp[0][0] = 1;
rep(i,h) {
rep(j,w) {
rep(k,1<<(w-1)) {
boo... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long dcsum(long long x) { return x * (x + 1ll) / 2ll; }
int main() {
long long m, b;
cin >> m >> b;
long long maxv = 0;
for (long long x = b * m; x >= 0; x -= m) {
long long y = b - x / m;
maxv = max(maxv, (y + 1ll) * dcsum(x) + (x + 1ll) * dcsum... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, l, r, s;
cin >> n >> l >> r >> s;
vector<int> x;
for (int i = 1; i <= r - l + 1; i++)
x.push_back(i);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const ll mod=1e9+7;
void solve()
{
ll n, k; cin>>n>>k;
ll a[n];
for(ll i=0; i<n; i++) cin>>a[i];
if(n==k) { cout<<1<<endl; return; }
vector<ll>go(n, 0);
ll ans=0;
for(ll i=1; i<n; i++)
{
if(a[i]>a[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
int t = 0;
int h = 0;
for (int i = 0; i < n; i++){
string T;
string H;
cin >> T >> H;
if (T > H){
t += 3;
} else if (T < H){
h += 3;
} else {
t++;
h++;
}
}
cout << t << ' ' << h <... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int n, m, ans;
int num[MAX_N];
pair<int, pair<int, int> > edge[MAX_N];
bool MARK[MAX_N];
int upd[MAX_N];
int UPD[MAX_N];
int dis[MAX_N];
vector<pair<int, pair<int, int> > > G[MAX_N];
int Arr[MAX_N + MAX_N];
int L, R;
int K[MAX_N];
vector<pair<int,... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 3e5 + 10;
const long long mod = 1e9 + 7;
const int base = 131;
const double pi = acos(-1);
const double eps = 1e-8;
long long vis[N], num[N], n, m, k, x, y, z;
long long a[N], b[N];
long long cx, cy, cnt, ans, sum, flag, t, ff, res;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct line {
int s, t;
long long dis;
bool operator<(line y) const { return dis < y.dis; }
} e[4000001];
struct point {
long long x, y;
} a[2001];
long long c[2001];
long long k[2001];
int tot = 0;
int fa[2005];
inline int findx(int x) {
if (fa[x] != x) fa[x] = f... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto vv : V) os << vv << ",";
return os << "]";
}... | 6 |
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
const int inf = ( 1 << 28);
int dp[20001][256];
int solve(int n,int m,int *cbook,int *in){
rep(i,n+1)rep(j,256)dp[i][j]=inf;
dp[0][128]=0;
rep(i,n){
rep(j,256){
if (dp[i][... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int ar[1000005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m, k, c = 0, f = 0, i, x;
cin >> n >> m >> k;
for (i = 0; i < m; i++) {
cin >> x;
mp[x] = 1;
}
int a = 1;
if (mp[1] == 1) {
cout << 1;
return... | 2 |
#include <bits/stdc++.h>
using namespace std;
int c[30];
int L;
char t[100010];
char s[100010];
int A, C;
int main() {
scanf("%s", t + 1);
L = strlen(t + 1);
for (int i = 1; i <= L; i++) c[t[i] - 'a']++;
for (int i = 1; i <= L; i++) {
A++;
s[A] = t[i];
c[s[A] - 'a']--;
while (C < 26 && !c[C]) C+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(NULL);
int n, f = 0, z = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 5)
f++;
else
z++;
}
if (z < 1)
cout << -1;
else {
int re... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int father[N];
vector<int> v[N], tree[N], dis[N], g[N];
int n, m, q;
set<int> st;
map<int, int> mp;
int tr[N];
int treenum = 0;
int L, R, nowdep;
int c[N], f[N], d_max[N];
map<pair<int, int>, double> ans;
map<pair<int, int>, int> flag;
int getfather(in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double sqr(double x) { return x * x; }
int main() {
double xp, yp, vp, R;
double x, y, v, r;
scanf("%lf%lf%lf %lf%lf%lf%lf", &xp, &yp, &vp, &x, &y, &v, &r);
R = sqrt(sqr(xp) + sqr(yp));
double R2 = sqrt(sqr(x) + sqr(y));
double thet... | 3 |
#include <bits/stdc++.h>
int main() {
int n, i, j, m, s = 0;
scanf("%d %d", &n, &m);
int arr1[m + 1];
for (i = 0; i <= m; i++) {
arr1[i] = 0;
}
for (i = 0; i < n; i++) {
scanf("%d", &j);
arr1[j]++;
}
for (i = 1; i < m; i++) {
for (j = i + 1; j <= m; j++) {
s += arr1[i] * arr1[j];
... | 2 |
#include<iostream>
using namespace std;
int main(){
int a, b, c;
cin >>a >> b >>c;
cout<< min(a+ b, min(b+c, a+c));
return 0;
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
inline long long rd() {
long long x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int modulo = 1e9 + 9;
int n, m;
int pare[1000000];
int identificador(int u) {
if (pare[u] == 0) return u;
int idpareu = identificador(pare[u]);
pare[u] = idpareu;
return idpareu;
}
int main() {
cin >> n >> m;
long long int sol = 1;
for (int i = 0; i ... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
const int mxn=1e3+3;
ll a[mxn][mxn],n,m;
ll sum[mxn],squsum[mxn];
pair<int,int> delta[mxn];
int err;
ll sumdelta,squsumdelta;
ll orgsum,orgsqusum;
ll sumchange,squsumchange;
ll deltasqusumchange,basesqusumchange;
ll ans;
inline void ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
int x, y;
cin >> a >> b;
cin >> x >> y;
if (a > b) swap(a, b);
if (x > y) swap(x, y);
if ((b != y) || (a + x != b))
cout << "NO\n";
else
cout << "YES\n";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t1, t2, x1, x2, t0;
double best = 0x3f3f3f3f, t;
pair<int, int> ans;
int main() {
cin >> t1 >> t2 >> x1 >> x2 >> t0;
double y1 = x1, y2 = x2;
while (y1 >= 0 && y2 >= 0) {
t = double(t1 * y1 + t2 * y2) / (y1 + y2);
if (t < t0) {
y1--;
continue;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> a[200100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < (n); i++) cin >> a[i].first;
for (int i = 0; i < (n); i++) cin >> a[i].second;
sort(a, a + n);
multiset<long long> s;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535;
string x;
int n, t, k;
int MOD = 1000000007;
int main() {
cin >> x;
n = x.length();
for (int i = 0; i < n; ++i) {
t <<= 1;
t += x[i] - '0';
t %= MOD;
}
for (int i = 0; i < n - 1; ++i) {
t <<= 1;
t %= MOD;
}
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
long long int sum, wanted;
int vol[N];
void read() {
cin >> n >> wanted;
for (int i = 0; i < n; i++) cin >> vol[i];
}
void init() {
for (int i = 0; i < n; i++) sum += vol[i];
}
int ans() {
for (int i = 1; i < n; i++) {
int dif = vol[i]... | 2 |
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
class QuickUnionFind {
private:
int size_; std::vector<int> g; std::vector<std::vector<int> > v;
public:
QuickUnionFind() : size_(0), g(std::vector<int>()), v(std::vector<std::vector<int> >()) {};
QuickUnionFind(int size__) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long f[205];
void init() {
f[0] = 0;
f[1] = 1;
for (int i = 2; i <= 90; i++) {
f[i] = f[i - 1] + f[i - 2];
}
}
int main() {
long long n;
while (~scanf("%lld", &n)) {
init();
long long ans = 0;
for (int i = 1; i <= 200; i++) {
if (f[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 12345678910;
const long double EPS = 1e-13;
const int INF = INT_MAX;
string s[1010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
if (n == 1) {
cout << 6 << endl;
r... | 3 |
#include <bits/stdc++.h>
using namespace std;
int mexx[100001];
int now[1000];
int minn[1000];
int mini[100001];
int main() {
int n;
scanf("%d", &n);
mexx[1] = 0;
mexx[2] = 0;
mexx[3] = 1;
mini[3] = 2;
int k;
int cnt = 0;
int de = 0;
int p = 0;
int j1;
for (int i = 0; i < 100000; i++) {
if (... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,mod=1e9+7;
typedef long long ll;
ll inv(ll x){return x==1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll f[N],invf[N],s[N];
ll C(int n,int m)
{
return f[n]*invf[n-m]%mod*invf[m]%mod;
}
int main()
{
f[0]=invf[0]=f[1]=invf[1]=1;
for(int i=2;i<N;i++) f[i]=f[i-1... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
long long x[N];
long long sum[N];
long long c[N], v[N];
int main() {
ios::sync_with_stdio(false);
int n, k, s, t;
cin >> n >> k >> s >> t;
for (int i = 0; i < n; i++) cin >> c[i] >> v[i];
for (int i = 0; i < k; i++) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n;
cin >> k;
vector<long long> a;
unordered_map<long long, long long> counts;
for (long long i = 0; i < n; ++i) {
long long v;
cin >> v;
a.push_back(v);
counts[v] += 1;
}
vector<long long> after;
vector... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<unsigned long long> ans(n);
n *= 2;
vector<pair<unsigned long long, unsigned long long>> a(n);
for (int i = 0; i < n; i += 2) {
cin >> a[i].first;
a[i].second = 1;
cin >> a[i + 1].first;
a[i + 1].first++... | 3 |
#include <bits/stdc++.h>
const int inf = 0x7FFFFFFF;
double eps = 1e-5;
using namespace std;
double k, b, N, T;
int main() {
cin >> k >> b >> N >> T;
long long C1 = -b + 1 - k;
long long C2 = -b + T * (1.0 - k);
long long beishu = 1;
int ans = 0;
if (!C1 || !C2) {
while (1)
;
} else if (C1 == C2... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
vector<int> p(3);
p[0] = 0;
p[1] = 1;
p[2] = 2;
long long ans = 1e9, cnt = 0;
string tmp, c = "GBR", ans1;
do {
tmp = "";
cnt = 0;
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int n;
cin >> n;
string s;
cin >> s;
long long int one = 0, zero = 0;
for (long long int i = 0; i < n; i++) {
if (s[i] == '1')
one++;
else
zero++;
}
cout << n - 2 * min(one, ... | 1 |
#include <bits/stdc++.h>
int k, b, n, a[100001];
std::unordered_map<int, int> mp;
int main(int argc, char const *argv[]) {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> k >> b >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
int cnt = 0;
lo... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
const int INF = (1<<30)-1;
int main(){
int n,m,a,b,c,sum,ma,hiku;
priority_queue<PA,vector<PA>,greater<PA> > pq;
while(cin >> n >> m,n!=0||m!=0){
sum = 0;
vector<PA> vec[100];
for(int i=0;i<m;i++){
cin >> a >> b >> c;
v... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 100333;
int N, M, Q;
vector<int> adj[SZ];
bool vis[SZ];
int height[SZ];
int getHeight(int u) {
if (vis[u]) return -1;
vis[u] = true;
int h = 0;
for (int v : adj[u]) h = max(h, 1 + getHeight(v));
return height[u] = h;
}
int g[SZ];
vector<int> fs[SZ];... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int A[10];
int B[10];
int Acopy[10];
int Bcopy[10];
int solve() {
for (int i = 0; i < 10; i++) {
Acopy[i] = A[i];
Bcopy[i] = B[i];
}
int res = 0;
for (int i = 0; i < 10; i++) {
int mx = min(Acopy[i], Bcopy[10 - i - 1]);
res += mx;
Acopy... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ctor(char n) {
switch (n) {
case '^':
return 0;
case '>':
return 1;
case 'v':
return 2;
case '<':
return 3;
}
}
int main() {
ios_base::sync_with_stdio(false);
string a, b;
int t;
cin >> a >> b >> t;
t %= 4;
if (t =... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int re_ad() {
int x = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
return x * f;
}
int n, k, q;
int a[200010], b[20001... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(20);
int n, m;
cin >> n >> m;
if (n == 1) {
cout << "0\n";
return 0;
}
vector<int> a(m);
for (int i = 0; i < m; ++i) {
cin >> a[i];
--a[i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int count = 0;
int n = str.size();
int temp[26] = {0};
for (int i = 0; i < n; i++) {
temp[str[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (temp[i] > 0) count++;
}
if (count % 2 == 0)
cout << "CHAT WIT... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int dx[4] = {-1, 0, 1, 0};
long long int dy[4] = {0, 1, 0, -1};
bool visited[1005][1005];
long long int n, m;
char a[1005][1005];
void dfs(long long int x, long long int y) {
visited[x][y] = 1;
for (long long int i = 0; i < 4; i++) {
long long int nx = x +... | 2 |
#include <bits/stdc++.h>
using namespace std;
void outsource(bool tell) {
if (tell) freopen("input.txt", "r", stdin);
}
bool check(long long int x1, long long int x2, long long int temp) {
if (x1 <= temp && temp <= x2) {
return true;
}
return false;
}
int main() {
int t;
cin >> t;
while (t--) {
lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
void CyBerForCe() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
cout << (((a ^ b) & (c | d)) ^ ((b & c) | (a ^ d))) << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
CyBerForCe();
return 0;
}
| 5 |
#include<bits/stdc++.h>
using namespace std;
int64_t t, n, m, k, a[1000005];
void solve(){
int odd = 0, even = 0;
for(int i = 1; i <= n + n; i++){
if(a[i] % 2 == 0) even++;
else odd++;
}
if(even == odd) cout << "Yes" << "\n";
else cout << "No" << "\n";
}
int main(){
ios_base:... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1100], b[1100];
int main() {
int n, k, d, i, tmp, cnt, j;
scanf("%d%d", &n, &k);
for (i = 1; i <= n; i++) scanf("%d", b + i);
for (i = 0; i < k; i++) a[i] = n - k + i + 1;
int kol = k;
for (cnt = n - k; cnt > 0; cnt--) {
for (j = 0, tmp = 0; tmp < b[cn... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MAXN = 1e6 + 5, inf = 1e9;
const ll INF = 1e18;
const ld PI = 3.1415926535897932384626433832795;
ll a[MAXN], b[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << setprecision(13) << fixed;
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = s;
int l = s.size();
stack<int> ss;
for (int i = 0; i < l; i++) {
if (s[i] == '0' && !ss.empty()) {
ss.pop();
} else if (s[i] == '1') {
ss.push(i);
}
}
while (!ss.empty()) {
ans[ss.top... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos((long double)-1);
const int inf = (int)1.01e9;
const long double eps = 1e-12;
vector<int> v;
vector<int> vv;
priority_queue<pair<long long int, int> > q;
int id[100002];
int im[100002];
void calc(int n, int r, vector<int> &vc) {
memset(im, 0, s... | 4 |
#include<iostream>
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 15
#define rep(i,n) for(int i=0;i<int(n);i++)
int nn,m;
vector<int> g[MAX],r[MAX];
bool used[1<<MAX][MAX];
struct Q{
bool is_move;
bool is_on;
int s;
bool operator<(const Q& q)const{return ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct tree {
pair<int, int> x;
int upd;
tree* left;
tree* right;
tree(int l, int r) {
this->x = {0, l};
this->upd = 0;
this->left = nullptr;
this->right = nullptr;
}
};
struct do... | 4 |
#include <algorithm>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
template<class T> inline void chmin(T& a, const T& b) { if(b < a) a = b; }
typedef int weight;
struct edge {
int to;
weight cost;
edge(... | 0 |
#include <bits/stdc++.h>
using namespace std;
int T, N, aux;
int dp[200];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> T;
dp[0] = 1;
for (int i = 3; i <= 100; i++)
if (dp[i - 3]) dp[i] = true;
for (int i = 7; i <= 100; i++)
if (dp[i - 7]) dp[i] = true;
while (T--) {
cin >> aux... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar(), f = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
}
int n, Q, K[100... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
pair<int, int> v[300111];
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
int dir = 0;
for (int i = 0; i < n + 1; i++) {
cin >> v[i].first >> v[i].second;
}
for (int i = 0; i < n; i++) v[i + n] = v[i];
int ans = 0;
for (int i = 0; i < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, tot, ans1, ans2, lim;
int vis1[300050], vis2[300050];
struct node {
int a, b, sit;
} in[300050], temp[300050], temp2[300050];
bool mycmp(node x, node y) { return x.b > y.b; }
bool mycmp2(node x, node y) { return x.b < y.b; }
int main() {
scanf("%d", &t);
for (i... | 4 |
#include <iostream>
using namespace std;
int main()
{
int n;
cin >> n;
int ans = 0, top = 0;
for(auto i = 0; i < n; ++i){
int h;
cin >> h;
if(h >= top){
++ans;
top = h;
}
}
cout << ans << endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int s[1050][1050];
int x[2], y[2], l, r;
int a, b, c, d, e, f;
int ri[2050050];
int dw[2050050];
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
;
for (; isdigit(c); c = getchar()) x = x * 10 + c... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s[111];
vector<int> a[1000];
int vis[111];
bool hasCycle;
int Int[1000], Ext[1000];
int graph[100][100];
int answer[1000];
int cnt;
void createGraph(int x, int y) {
int pos = 0;
bool found = false;
while (pos < s[x].size() && pos < s[y].size() && !found) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
string mat[n];
int arr[n];
for (int i = 0; i < n; i++) {
cin >> mat[i];
arr[i] = 0;
}
int ans = 0;
int i, j;
for (i = 0; i < m; i++) {
vector<int> vec;
for (j = 1; j < n; ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n, r;
cin >> n >> r;
double each = ((n - 2) * 180) / n;
double a1, b;
a1 = each / 2;
b = 180 - each;
a1 = a1 * 3.14159265358979323846 / 180;
b = b * 3.14159265358979323846 / 180;
cout << fixed << setprecision(7) << (r * sin(b)) / (2 * s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 1;
const long long nol = 0;
long long n, a, cnt, ans;
deque<string> v;
map<string, long long> mp;
string g, s, h;
void vkoshp() {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> g >> s;
if (i != n - 1) cin >> h;
reverse(s.begin... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float n, i, s = 0, a;
float p;
cin >> n;
for (i = 1; i != n + 1; i++) {
cin >> a;
s += a;
}
p = s / n;
cout << fixed << setprecision(12) << p;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 444;
vector<int> g[NMAX];
int n, m;
int d[NMAX][NMAX];
void bfs(int s) {
for (int i = 1; i <= n; i++) d[s][i] = -1;
d[s][s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int here = q.front();
q.pop();
for (int there : g[here]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.size();) {
int j = i + 1;
for (; j < s.size(); j++) {
if (s[i] != s[j]) break;
}
if ((j - i) % 2) {
for (int k = i + 1; k < j; k += 2) {
s[k] = s[i] == 'a' ? 'b' : 'a';
}
... | 3 |
#include <cmath>
#include <vector>
#include <iomanip>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <limits>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<PII> V... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[100005], b[100005], za[100005], zb[100005];
long long num, den, z;
const long long pri = 1e9 + 7;
long long myPow(long long a, long long b) {
long long ret = 1;
while (b != 0) {
if (b % 2 != 0) {
ret = (ret * a) % pri;
}
b /= 2;
a... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 2e5 + 9;
const long long INF = 1e12;
long long N, M, f, s, res;
signed main() {
ios_base::sync_with_stdio(false);
cin >> N >> M;
for (int A = 1; A <= M; A++) {
for (int B = 1; B <= M; B++) {
if (((A * A) % M + (B * B) % M) % M) continue... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<pair<int, int> > v;
map<char, int> m, n;
string s;
int x, y;
scanf("%d %d", &x, &y);
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (m[s[i]] == 0) {
m[s[i]] = 1;
v.push_back(make_pair(i, 1));
}
}
for (int i = s.... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int id, to;
long long weight;
edge() {}
edge(int i, int t, long long w) : id(i), to(t), weight(w) {}
bool operator<(const edge& rhs) const { return weight > rhs.weight; }
};
const int N = 3e5 + 5;
int n, m, k;
long long dis[N];
vector<edge> edges[N];... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
ans += x * i;
}
cout << ans;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Universe {
vector<T> o;
void push(const T &x) { o.push_back(x); }
int build() {
sort(o.begin(), o.end());
o.resize(unique(o.begin(), o.end()) - o.begin());
return o.size();
}
int find(const T &x) {
auto it = lower_bound... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s;
cin >> s1 >> s2;
int i = 0;
int k = 0;
while (i < s1.size()) {
if (s1[i] != s2[i]) {
k++;
if (k & 1)
if (s1[i] == '1')
s += "0";
else
s += "1";
else if (s2[i] == '1')
... | 2 |
#include <bits/stdc++.h>
using namespace std;
double s[450][450], f[450];
int n, m, a, b, c, d, su;
void pivot(int n, int m, int x, int y) {
double tp = s[y][x];
s[y][x] = -1;
for (int i = 1; i <= m + 1; i++) s[y][i] /= -tp;
for (int i = 1; i <= n; i++)
if (i != y) {
double tp = s[i][x];
s[i][x]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long n, a[100069];
int main() {
long long i, e;
pair<long long, long long> mne = {inf, -1};
scanf("%lld", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", a + i);
}
for (i = 1; i <= n; i++) {
mne = min(mne, {abs(a[i] - a[i %... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (a && b) {
if (a < b) swap(a, b);
a = a % b;
}
return a + b;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
long long p, q, b;
for (int i = 0; i < n; i++) {
cin >> p >> q >> b;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int id[200005], A[200005];
vector<int> v;
void init() {
for (int i = 0; i < 200005; ++i) {
id[i] = i;
}
}
int root(int x) {
while (x != id[x]) {
id[x] = id[id[x]];
x = id[x];
}
return x;
}
void union1(int x, int y) {
int p = root(x);
int q = root(y... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, a, b, p, c, d, e, f, g, h, hh, i, j;
cin >> t;
while (t--) {
cin >> a >> b >> p;
string s;
cin >> s;
vector<long long> v;
vector<long long> ans;
long long k = 0;
for (i = 0; i < s.length();) {
j = i;
... | 2 |
#include <bits/stdc++.h>
int ex[3];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
ex[i % 3] += x;
}
if (ex[0] > ex[1] && ex[0] > ex[2])
printf("chest\n");
else if (ex[1] > ex[0] && ex[1] > ex[2])
printf("biceps\n");
else
printf("back\n")... | 1 |
#include <iostream>
int main(){
int a,b;
std::cin >> a >> b;
printf("%d",a*b/2);
} | 0 |
#include<stdio.h>
typedef long long ll;
const int N=500005,P=998244353;
int fexp(int a,int b)
{
ll x=1,o=a;
for(;b;b>>=1,o=o*o%P)
if(b&1)x=x*o%P;
return x;
}
int n,m,ans,fac[N],ifac[N];
int C(int n,int m){return 1ll*fac[n]*ifac[n-m]%P*ifac[m]%P;}
int main()
{
scanf("%d%d",&n,&m);
if(n<m){
int t=n;
n=m;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
int x = max(a, b);
int y = min(a, b);
if (!y)
return x;
else
return gcd(y, x % y);
}
int main() {
int num, temp, mx = -1;
cin >> num;
int tk = 0;
for (int i = 0; (i) < (num); i++) {
cin >> temp;
tk = gcd(tk, temp);
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
int z[1000001];
void zAlgo() {
int L = 0, R = 0;
for (int i = 1; i < s.length(); i++) {
if (i > R) {
L = R = i;
while (R < s.length() && s[R - L] == s[R]) R++;
z[i] = R - L;
R--;
} else {
int k = i - L;
if (z[k] < R ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
while(1){
int n; string s; cin >> n; if(n==0) return 0; cin >> s;
int dp[(1<<10)+5]={};
int cur = 0;
for(int i=0;i<n;i++){
if(s[i] == 'u'){
cur = 0;
}
else{
dp[cur] |= (1<<(s[i]-'0')); //cout << cur << " " << (1<<(s[i]-'0'));
cur |=... | 0 |
#include<iostream>
using namespace std;
int n,a[100010],b[100010];
int main()
{
long long cnt=0;
cin>>n;
for(int i=0;i<=n;i++)
cin>>b[i];
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=n-1;i>=0;i--)
{
if(a[i]>b[i+1])
{
cnt+=b[i+1];
a[i]-=b[i+1];
b[i+1]=0;
if(a[i]>b[i])
cnt+=b[i],b[i]=0;
el... | 0 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long ModPow(unsigned long long base, unsigned long long exp,
unsigned long long m) {
unsigned long long r = 1, p;
base %= m;
while (exp) {
if (exp & 1) r = (r * base) % m;
exp = exp >> 1;
base = (base * base) % m;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353ll;
int N, T;
int sol[307];
int otherVal;
int sum = 0;
int main() {
scanf("%d %d", &N, &T);
otherVal = T;
for (int i = N - 1; i >= 1; i--) {
for (int j = 0; j < 20; j++) {
printf("? %d %d\n", 1, i);
printf("? %d %d\n", 1,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2;
int a, b;
scanf("%d%d", &h1, &h2);
scanf("%d%d", &a, &b);
if (a <= b && h1 + a * 8 < h2) {
printf("-1\n");
} else {
int cnt = 0;
int now = h1 - 4 * a;
while (now + a * 12 < h2) {
now += a * 12;
now -= b * 12;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
long long cnt = 0, i, ans = 0, d;
cin >> a;
if (a.size() == 1) ans--;
do {
cnt = 0;
for (i = 0; i < a.size(); i++) cnt += a[i] - 48;
d = cnt;
a = "";
while (d > 0) {
a += d % 10 + 48;
d /= 10;
}
ans++;... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
char s[200];
node* nxt[200];
int son, f;
node() {
son = 0;
f = 0;
}
} * p;
char path[200][200];
int n, file;
void insert(char ss[]) {
int i;
for (i = 0; i < p->son; i++) {
if (strcmp(ss, p->nxt[i]->s) == 0) {
p = p->nxt[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
int n;
vector<vector<pair<int, ll>>> ps;
vector<map<int, ll>> memo, memo2;
ll dfs2(int i, int from);
ll dfs(int i, int from) {
if (memo[... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
const int M = 2e5 + 10;
char ch[N], p[N], s[M], a[10], b[10];
int main() {
int n, m;
while (~scanf("%d %d", &n, &m)) {
for (int i = 'a'; i <= 'z'; i++) {
ch[i] = i;
}
scanf("%s", s);
while (m--) {
scanf("%s %s", a, b);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e3 + 4;
long long int dp[mxN][mxN], ar[mxN], br[mxN];
int main() {
int n, m, a, i, j;
cin >> n;
for (i = 1; i <= n; i++) cin >> ar[i], ar[i] -= i, br[i] = ar[i];
sort(br + 1, br + n + 1);
for (i = 1; i <= n; i++) {
dp[i][1] = dp[i - 1][1] + ab... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.