solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int const N = 150 + 20;
int n, a[N], dp[N][N], full[N][N][N];
string s;
bool pal[N][N], mark[N][N][N];
void sMax(int &a, int b) { a = max(a, b); }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch = 1;
vector<int> v;
v.push_back(1);
while (ch != '=') {
scanf(" %c", &ch);
if (ch == '?') continue;
if (ch == '+') v.push_back(1);
if (ch == '-') v.push_back(-1);
}
int n;
scanf("%d", &n);
int men = 0, mai = 0;
for (int... | 1 |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=1e5+10;
int n,ord[maxn],cnt,deg[maxn],ans1[maxn],ans2[maxn];
vector<int> vec[maxn],g[maxn];
int main(){
scanf("%d",&n);
for(int i=1,u,v;i<n;++i){
scanf("%d%d",&u,&v);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int main() {
int n;
cin >> n;
vector<int> fs(n);
vector<int> c(n);
vector<vector<int> > dp(n, vector<int>(3, INT_MAX));
for (int i = 0; i < n; i++) {
cin >> fs[i];
}
for (int i = 0; i < n; i++) {
cin >> c[i];
dp[i][0] = c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, k, target, number, count = 0, position;
cin >> n >> k;
vector<long long> a;
for (i = 0; i < n; i++) {
cin >> number;
a.push_back(number);
}
while (n--) {
if (a[n] != a[n - 1]) {
count = n;
break;
}
}
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
long long v[maxn], t[maxn], sum[maxn];
long long num[maxn];
long long remain[maxn], len[maxn];
long long n;
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &v[i]);
for (int i = 1; i <= n; i++) {
scanf("%lld", &... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k;
long long n, m;
cin >> n;
m = sqrt(n * 2);
j = m * (m + 1) / 2;
if (j > n) {
m--;
j = m * (m + 1) / 2;
}
k = n % j;
if (!k)
cout << m << endl;
else
cout << k << endl;
return 0;
}
| 1 |
#include<iostream>
using namespace std;
int main()
{
for(;;){
int x, y;
int map[100][100];
int dp[100][100];
cin >> x;
cin >> y;
if(x == 0 && y == 0){
break;
}
for(int i = 0; i < y; i++){
for(int j = 0; j < x; j++){
cin >> map[i][j];
}
}
//ツ鳴催渉可づ可暗ェツ氾板湘」ツづ個療アツづ個づつィツづィツ青板づーツ個... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3c3c3c3c;
const long long infl = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 1e5 + 9;
int ans[MAX_N];
int main() {
cin.tie(NULL);
cin.sync_with_stdio(false);
cout.sync_with_stdio(false);
string str;
cin >> str;
int strSz = str.size();
int ansSz = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int NR = 1e6 + 5;
const int MR = 1e6 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
inline int read() {
int x = 0;
int bei = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') bei = -1;
ch = getchar();
}
while (ch >= '... | 3 |
#include <bits/stdc++.h>
using namespace std;
int is_pri[100 + 10];
int a[5 * 10000 + 10];
int ape[100 + 10];
int main() {
int n;
memset(is_pri, 0, sizeof(is_pri));
for (int i = 2; i <= 100; i++) {
if (is_pri[i] == 0) is_pri[i] = 1;
for (int j = 2; j * i <= 100; j++) {
if (is_pri[i * j] == 0) is_pri... | 2 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P2;
const int inf=1000000000;
int dp[101][101][301]={};
ll w1[101]={};
int v1[101]={};
ll km[101]={};
int... | 0 |
#include <bits/stdc++.h>
struct point {
int x, l;
} pp[1000000 * 2];
int qq[1000000 * 2], sk;
int pcompare(const void *a, const void *b) {
struct point *pa = (struct point *)a;
struct point *pb = (struct point *)b;
return pa->x != pb->x ? pa->x - pb->x : pb->l - pa->l;
}
void sort(struct point *pp, int n) {
i... | 4 |
#include <bits/stdc++.h>
const int inf = 1061109567;
const double eps = 1e-9;
using namespace std;
int n, m;
inline int pw(int a, int b, int c) {
if (!b) return 1 % c;
int r = pw(a, b / 2, c);
r = (1ll * r * r) % c;
if (b % 2) r = (1ll * r * a) % c;
return r;
}
int main() {
scanf("%d%d", &n, &m);
int res ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
int a[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1, sm = a[i]; j <= n + 1; j++) {
if (sm > 100 * (j - i)) ans = max(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1);
const int M = 3e5 + 10;
const int inf = 2e9 + 10;
const int mod = 998244353;
int q, n, a[M], dp[M], nxt[M];
map<int, int> mp[M];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> q;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cin.exceptions(cin.failbit);
long long p, k;
cin >> p >> k;
vector<int> ans;
while (p >= k) {
ans.push_back(p - (p / k) * k);
p = p / k;
ans.push_back((p + k - 1) / k * k - p);
p = (p + k - 1) / ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, q;
scanf("%lld %lld %lld", &n, &m, &q);
long long a[n][m];
long long b[q], d[q], cou = 0, t, r, c, x;
for (long long i = 0; i < q; i++) {
scanf("%lld", &t);
if (t == 1) {
scanf("%lld", &r);
b[cou] = t;
d[cou] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(NULL);
int tc;
cin >> tc;
while (tc--) {
long long n, m;
cin >> n >> m;
long long ans = 0;
long long d = n / 2;
ans += d * m;
if (n % 2 == 1) {
long long q = ceil(m / 2.00)... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, cnt, sum, len, tlen, tcnt;
int a[26], ans[N], tans[N], id[26], pos[N], tpos[N];
void work1() {
printf("0\n");
for (int i = 0; i < n; i++)
for (int j = 1; j <= a[i]; j++) printf("%c", 'a' + i);
}
bool cmp(int x, int y) { return a[x] > a[y... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
const int N = (int)1e5 + 9, K = 10, F = (int)1e4 + 7;
struct node {
node *l, *r;
int val, prio, sz;
node(int v) : l(NULL), r(NULL), val(v), prio(rd()), sz(1) {}
} * root[F], *ll, *mm, *rr;
int sz(node... | 5 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
size_t n;
std::cin >> n;
std::vector<int32_t> a(n);
int32_t sum = 0;
for (size_t i = 0; i < n; ++i) {
std::cin >> a[i];
sum += a[i];
}
if (sum % 3 != 0) {
std::cout << "0\n";
return 0;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
vector<int> f, col, wlk;
int Find(int a) {
if (f[a] == a) return a;
int fa = Find(f[a]);
f[a] = fa;
return fa;
}
void Union(int a, int b) {
int fa = Find(a);
int fb = Find(b);
if (fa == fb) return;
wlk[fa] ... | 4 |
#include <iostream>
using namespace std;
int main()
{
char p,q;
int a,b,c;
int x=0,y=0;
while(cin >> a >> p >> b >> q >> c)
{
if(a*a+b*b==c*c) x++;
if(a==b) y++;
}
cout << x << endl << y << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int square[] = { 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289 };
int ans;
void dfs(int num, int upper){
//cout << num << "\t" << upper << endl;
for (int i = upper; i >= 0; i--){
if (num > square[i]) dfs(num - square[i], i);
else if (num ... | 0 |
#include <bits/stdc++.h>
#define ed end()
#define bg begin()
#define mp make_pair
#define pb push_back
#define all(x) x.bg,x.ed
#define newline puts("")
#define si(x) ((int)x.size())
#define rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=0;i<n;++i)
#define srep(i,s,t) for(int i=s;i<=t;++i)
#define drep(i,s... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
int inf=1000001000;
ll INF=100000000000000000;
int main() {
int n,m;
cin ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long n, k, i, j, x;
map<long, long> b;
priority_queue<pair<long, long> > c;
int main() {
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> x;
b[x]++;
}
for (i = 0; i < b.size(); i++)
if (b[i] != 0)
for (j = 1; j <= b[i]; j++) c.push(make_pair(b[i] / ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 20000;
int n, m;
vector<vector<int>> capacity;
vector<vector<int>> adj;
int bfs(int s, int t, vector<int>& parent) {
fill(parent.begin(), parent.end(), -1);
parent[s] = -2;
queue<pair<int, int>> q;
q.push({s, INF});
while (... | 5 |
#include <bits/stdc++.h>
using namespace std;
void secrets() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k;
vector<pair<int, pair<int, int>>> b;
long long counter = 0;
int main() {
secrets();
cin >> n >> k;
b.resize(n + 2);
for (int i = 0; i < n; i++) {
b[i].first = 0;
... | 1 |
#include<iostream>
using namespace std;
int main()
{
int A,B,C;
cin>>A>>B>>C;
if (A*B*C==175)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
template <class U, class T>
void Max(U &first, T second) {
if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
if (first > second) first = second;
}
template <class T>
voi... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int main() {
int n, v, f = 0, m = 0, r = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &v);
r = max(r - v, m + v);
m = max(m + v, f - v);
f -= v;
}
printf("%d\n", max(f, max(m, r)));
return 0;
}
| 3 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int h,w,x,y;
cin >> h >> w >> x >> y;
if(h*w%2==1 and (x+y)%2==1){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n;
int d[1 << 16], s[1 << 16];
vector<pair<int, int> > ans;
int main() {
cin >> n;
set<pair<int, int> > m;
for (int i = 0; i < n; i++) {
cin >> d[i] >> s[i];
m.insert(pair<int, int>(d[i], i));
}
while (!m.empty()) {
pair<int, i... | 1 |
#include <bits/stdc++.h>
using namespace std;
//#define int long long
const int mod = 1e9+7;
int dp[10003][100][2];
int main(){
string K;
int D;
cin >> K >> D;
int n = K.length();
for(int i = 0; i < K[0] - '0'; i++){
dp[0][i%D][0]++;
}
dp[0][(K[0]-'0')%D ][1]++;
for(int i = 1; i < n; i++){
for(int j... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 2;
const int M = 1e3 + 2;
int num[N][M];
int flag[N];
int id[N][2];
int res[M][2];
int op[N];
int n, m;
map<string, int> has;
int ress[M][2];
int ans1[M];
int ans2[M];
void check(int val) {
for (int i = 0; i < m; i++) num[0][i] = val;
for (int i = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int S, T;
struct dat {
int to, rev, f, cap;
dat(int to = 0, int rev = 0, int f = 0, int cap = 0)
: to(to), rev(rev), f(f), cap(cap) {}
};
vector<dat> v[11000];
int a[11000], b[11000], c[11000], l[11000], r[11000], st[11000];
int dist[11000];
queue<int> q;
int work... | 4 |
#include<bits/stdc++.h>
using namespace std;
int Decoding(char c,int key){
int num;
if(c >= 'A' && c <= 'Z'){
num=c-65;
}else{
num=c-71;
}
num=(num+51*key)%52;
return num;
}
int main(){
char list[52];
string str;
int n;
int key[100];
for(int i=0 ; i+65 <= 90 ; i++)list[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int k1, k2;
cin >> k1;
queue<int> a;
for (int i = 0; i < k1; i++) {
int x;
cin >> x;
a.push(x);
}
cin >> k2;
queue<int> b;
for (int i = 0; i < k2; i++) {
int x;
cin >> x;
b.push(x);
}
int count = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void print(vector<T> a) {
int n = a.size();
for (long long i = 0; i < n; ++i) {
cout << a[i] << (i == n - 1 ? "\n" : " ");
}
}
int sum_vector(vector<int> v) { return accumulate(v.begin(), v.end(), 0); }
void sort_vector(vector<int> &v) { sort(v.... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, l, r, c, pl, pr, cl, cr;
cin >> a >> b >> l >> r;
c = a + b;
cl = --l / c;
cr = --r / c;
pl = l % c;
pr = r % c;
if (cl == cr) {
if (pl < a && pr < a) {
cout << pr - pl + 1 << endl;
} else if (pl < a && pr >= a) {
c... | 1 |
#include <iostream>
using namespace std;
int n,q;
int dat[300000];
void init(){
int nn = 1;
while(nn < n) nn *= 2;
n = nn;
for(int i = 0;i < n * 2 - 1;i++){
dat[i] = 0;
}
}
void update(int a,int b,int x,int k,int l,int r){
if(r <= a || b <= l) return;
if(a <= l && r <= b){
dat[k] += x;
return;
}
updat... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Z = 2500, BASE = 1e9 + 7;
int n, k;
long long f[55][55][5050];
long long dp(int i, int j, int sum)
{
if (i > n)
return j == 0 && sum == k;
long long &res = f[i][j][sum + Z];
if (res >= 0)
return res;
res = dp(i + 1, j, sum);
if (j)
{
res... | 0 |
#include <bits/stdc++.h>
typedef struct {
double x;
double y;
double r;
} circle;
typedef struct {
double x;
double y;
} pt;
int x[3];
int y[3];
int r[3];
pt np(double x, double y) {
pt q;
q.x = x;
q.y = y;
return q;
}
double abs_d(double d1) {
if (d1 > 0) return d1;
return -d1;
}
bool flag2 = tru... | 3 |
#include <bits/stdc++.h>
#define N 2005
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
int gets(){
int v=0; char ch; bool f=0;
while(!isdigit(ch=getchar())) if(ch=='-') f=1; v=ch-48;
while( isdigit(ch=getchar())) v=(v<<3)+(v<<1)+ ch-48;
return f?-v:v;
}
char ch[N];
int T,n,m,ans[15],t,v,... | 3 |
#include <bits/stdc++.h>
const int inf = (1ll << 30) - 1;
const int maxn = (int)1e5 + 10;
using namespace std;
long long L[111], R[111], SHIFT[111], SHIFTVAL[111];
int sz = 1;
void upd1() {
long long x, k;
scanf("%lld%lld", &x, &k);
int g = 1;
while (R[g] < x) g++;
SHIFTVAL[g] -= k;
SHIFTVAL[g] %= (R[g] - L... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, t[100100];
int dp[100100];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &t[i]);
for (int i = 0; i < n; i++) {
int x = 1000000000;
if (i == 0)
x = 20;
else {
x = dp[i - 1] + 20;
int ini = 0, fim = i - 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, w[100005], ans;
double f[1050000], a[1050000];
char S[100005];
void fwt(double a[], int n, int d = 1) {
if (d > 0)
for (int m = 2, k = m >> 1; m <= n; m <<= 1, k <<= 1) {
for (int i = 0; i < n; i += m)
for (int j = i; j < i + k; ++j) {
... | 5 |
// 2020.12.13
// Code by LTb
// #pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define debug puts("QwQ");
inline int read(){
int x=0,f=1;
char ch;
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, i, j, k, head[N], adj[N * 2], nxt[N * 2], mn[N], Mn[N], pt[N], Pt[N],
dep[N], fa[N], ans[N], cnt;
bool v[N];
void Print() {
printf("%d", cnt);
for (int i = 1; i <= cnt; ++i) printf(" %d", ans[i]);
puts("");
}
void work(int x, int d)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n], b[m];
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0; i < m; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + m);
int index = 0;
for (long long i = 0; i < m; i++)
if (index < n && a[inde... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long add(long long a, long long b) {
(a += b) %= M;
(a += M) %= M;
return a;
}
long long mul(long long a, long long b) {
(a *= b) %= M;
(a += M) %= M;
return a;
}
long long fastpo(long long a, long long x) {
if (x == 0) return... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s;
cin >> s;
string res = "BGR";
int cnt = mod;
string ans;
do {
int mn = 0;
string aux = s;
for (int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int Inf = 1LL << 62;
int ar[Max];
int main() {
int n, mx = 0, mn = 1e9;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &ar[i]);
mn = min(mn, ar[i]);
mx = max(mx, ar[i]);
}
... | 4 |
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
int read() {
int x = 0, f = 1; char ch;
while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Max(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void Min(T &a, T b) {
if (a > b) a = b;
}
int a[200005];
double cal(double first, int n) {
double s = 0, mi = 0, mx = 0;
for (int i = 1; i <= n; i++) {
s += a[i] - firs... | 3 |
#include <bits/stdc++.h>
using namespace std;
char cells[1001][1001] = {0};
int scope[1001][1001] = {0};
int processNum[100001] = {0};
int ans[100001] = {0};
int pictFound = 0;
int nCells, mCells, startingPoint, rowPos, colPos, maxPict, i;
void visit(int rowPos, int colPos) {
if (rowPos == 0 || colPos == 0 || rowPos ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, m;
cin >> n >> m;
if (n % m == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t = 1;
cin >> t;
while (t--) {
... | 1 |
#include <bits/stdc++.h>
const int N = 100010, INF = 1e9 + 10;
std::vector<std::pair<int, int>> get_ancestors(int x, int y) {
std::vector<std::pair<int, int>> res;
res.push_back(std::make_pair(x, y));
for (int i = 0; i < 30; i++) {
if (x >> i & 1) {
assert(~y >> i & 1);
x ^= 1 << i;
res.push... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e6 + 9;
int n, m;
char a[sz], b[sz];
int arr[sz];
int cs[sz];
int ans;
int main() {
scanf("%s %s", a, b);
n = strlen(a);
m = strlen(b);
for (int i = 0; i < n; i += m) {
for (int j = 0; j < m; j++) arr[i + j] = (a[i + j] != b[j]);
}
cs[0] = ar... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a, b;
int day = 0;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
if (a > day)
day = a;
else {
while (a <= day) a += b;
day = a;
}
}
cout << day << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e+15;
const long long int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<pair<int, int> > A, B;
int n, x;
cin >> n;
vector<int> ans;
for (int i = (0); i < (n); i++) {
cin >> ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
set<int> s;
int n, L;
int lo, hi, mid;
int fin(int tar) {
lo = 0;
hi = n - 1;
while (lo <= hi) {
mid = (lo + hi) / 2;
if (a[mid] > tar)
hi = mid - 1;
else
lo = mid + 1;
}
if (hi >= 0 && a[hi] == tar) return 1;
return 0;
}
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
const char dir[] = {'R', 'L', 'D', 'U'};
ll add(ll a, ll b) {
a += b;
if (a >= MOD) {
a -= MOD;
}
return a;
}
int sub(int a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const static int N = 3e5 + 2;
const static int alpha = 26, K = 550;
int trie[N][alpha], cnt[N], sz;
void init() {
memset(trie[0], 0, sizeof trie[0]);
sz = 0;
}
void add(int l, const string &s, int x) {
int v = 0;
for (int i = l; i < s.size(); ++i) {
int c = s[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long OO = 1e18;
const int mod = 1e... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s[105];
vector<string> v;
int a[105];
int main() {
memset(a, 0, sizeof(a));
int n;
int ans = 0;
string home;
cin >> n >> home;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i].substr(0, 3) == home) {
v.push_back(s[i].substr(5, 3));
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int cor[n], wro[m];
for (int i = 0; i < n; i++) cin >> cor[i];
for (int i = 0; i < m; i++) cin >> wro[i];
int tl;
sort(cor, cor + n);
sort(wro, wro + m);
int v = max(2 * cor[0], cor[n - 1]);
if (v < wro[0])
cout ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, i, j, k;
long long int a[5050];
long long int mini = 1000000100, maxi = -1, res, sum = 0;
long long f(long long int l, long long int r, long long int x) {
if (l > r) return 0;
long long int t = min_element(a + l, a + r + 1) - a;
return min(r - l + ... | 3 |
#include<iostream>
using namespace std;
int map[110];
bool solve() {
if (map[1] % 2 == 1 && map[2] % 2 == 1) {
for (int i = 3; i <= 100; i++){
if (map[i] % 2 == 1)
return false;
}
return true;
}
else return false;
}
int main() {
int a, b;
while (cin >> a >> b) {
if (!a && !b) {
if (solve()) cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (1ll << 62) - 1;
const long long MOD = 1e9 + 7;
const int MAX = 1e9;
const long long int N = 1e6 + 100;
using namespace std;
vector<int> factor(N, -1), primes;
int bPow(int a, int b) {
int res = 1;
while (b) {
if (b & 1ll) {
res = 1ll * r... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e8;
const int N = 1001;
int n, m, x, y, pref[N], arr[N], dp[N][2];
char c;
int solve(int idx, int t) {
if (!idx) return dp[idx][t] = 0;
if (idx < x) return dp[idx][t] = INF;
int& ret = dp[idx][t];
if (ret) return dp[idx][t];
ret = INF;
for (int ... | 3 |
#include <iostream>
using namespace std;
int main()
{
int n,c=0;
cin>>n;
int arr[n];
for(int i=1;i<=n;i++){
cin>>arr[i];
if(i%2==1&&arr[i]%2==1){
c++;
}
}
cout<<c;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int x = a + b, y = c + d;
x = max(x, y);
cout << x << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int fc[100005], fp[100005], h[15];
int dp[505][5042], ans, n, k;
int main() {
cin >> n >> k;
for (int i = k * n, x; i--; ++fc[x]) cin >> x;
for (int i = n, x; i--; ++fp[x]) cin >> x;
for (int i = 1; i <= k; cin >> h[i++])
;
for (int x = 0, y, i; x < n; ++x)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, aux, T, R;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &R);
int sum = 0;
for (int i = 1; i < n; i++) scanf("%d", &aux), sum += aux;
printf("%d\n", (R % n + n - sum % n + n - 1) % n + 1);
}
return 0;
}
| 1 |
#include<iostream>
using namespace std;
int f;
char c;
int main(){
while(cin>>c)f^=1<<(c-97);
cout<<(f?"No":"Yes")<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> &f, pair<int, int> &s) {
if (f.first > s.first) {
return true;
}
if (f.first == s.first) {
if (f.second < s.second) {
return true;
} else {
return false;
}
}
return false;
}
int main() {
ios_base::sync_with_st... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, c = getchar(), f = 0;
for (; c > '9' || c < '0'; f = c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; x = (x << 1) + (x << 3) + c - '0', c = getchar())
;
return f ? -x : x;
}
inline void write(int x) {
if (x < 0) putch... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
while(n--){
double x1,x2,x3,y1,y2,y3;
cin>>x1>>y1>>x2>>y2>>x3>>y3;
double a,b,c;
a=pow((x2-x3),2)+pow((y2-y3),2);
b=pow((x3-x1),2)+pow((y3-y1),2);
c=pow((x1-x2),2)+pow((y1-y2),2);
double ox,oy;
ox=(a*(b+c-a)*x1+b*(c-b+a)*... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const double pi = acos(-1.0), eps = 1e-6;
double dist(int x, int y) { return sqrt((long long)x * x + (long long)y * y); }
struct Range {
double l, r;
bool operator<(const Range &b) const {
return fabs(l - b.l) < eps ? r > b.r : l < b.l;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
long long n = s.length();
long long st_row[] = {4, 5, 6, 3, 2, 1};
long long i, m = 0, ans = 0;
for (--n, i = 0; i < n; i++) {
m = m * 10 + (s[i] - '0');... | 2 |
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
scanf("%d%d",&n,&m);
printf("%d\n",m==1?0:n-m);
return 0;
}
| 0 |
#include <bits/stdc++.h>
int main() {
int a, b, c = 0, d = 0;
scanf("%d%d", &a, &b);
int m[1005] = {0}, n[1005] = {0};
for (int i = 0; i < a; i++) {
scanf("%d", &m[i]);
}
for (int i = 0; i < b; i++) {
scanf("%d", &n[i]);
}
for (int i = 0; i < a; i++) {
if (n[c] >= m[i]) {
c++;
d+... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1E9;
long long M = 1E9 + 7;
inline long long power(long long a, long long p) {
long long res = 1, x = a;
while (p) {
if (p & 1) res = (res * x);
x = (x * x);
p >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(N... | 3 |
#include <bits/stdc++.h>
using namespace std;
char A[2005];
int ctos, debe, va;
long long D[2005][2005], modd = 1000000007, suma;
int main() {
scanf("%d%d%s", &ctos, &debe, A + 1);
for (int queda = 0; queda <= debe; queda++) {
suma = 0;
if (queda == 0) suma = 1;
for (int dnde = ctos + 1; dnde > 0; dnde-... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) { return x * x; }
int mysqrt(long long x) {
int l = 0, r = 1e9 + 1;
while (r - l > 1) {
int m = (l + r) / 2;
if (m * (long long)m <= x)
l = m;
else
r = m;
}
return l;
}
mt19937 rnd(chrono::high_resolution_clock::now... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int dat[128];
pair<int, int> d2[128];
int gcd(int a, int b) {
while (b) {
int tmp = a % b;
a = b;
b = tmp;
}
return a;
}
vector<int> cand;
int ans = INT_MAX;
vector<int> anscand;
void rec(int lower) {
if (cand.size() > n) {
return;
}
int c... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long C, h1, h2, w1, w2;
int main() {
cin >> C >> h1 >> h2 >> w1 >> w2;
long long asd = C / w1, ans = 0;
for (long long i = asd, k = 1; i >= 0 && k <= 10000000; i--, k++) {
long long left = C - i * w1;
left /= w2;
ans = max(ans, i * h1 + left * h2);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a[310], b[310], i, d[310][310], j, k, n, m,
timer = 0, l, r, x, y, len, prevv[310], now[310], mx[310], mn[310];
int c[1011000], cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0, res[1110];
deque<int> v;
d... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, A[100], i, j;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> A[i];
}
sort(A, A + n);
cout << A[n - k];
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> gp[100001];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, s;
cin >> n >> s;
for (long long i = 0; i < n - 1; i++) {
long long a, b;
cin >> a >> b;
gp[a].push_back(b);
gp[b].push_back(a);
}
long... | 2 |
#include <cstdio>
using namespace std;
char map[8][8];
void check(void);
int main()
{
while (scanf(" %c", &map[0][0]) != EOF){
for (int i = 1; i < 8; i++){
scanf(" %c", &map[0][i]);
}
for (int i = 1; i < 8; i++){
for (int j = 0; j < 8; j++){
scanf(" %c", &map[i][j]);
}
}
check();
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147000000;
const long long inf = 1e18;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
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;
} ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int ST = 100010;
const int ST1 = 1000010;
const long long MOD = 1000000007;
long long ABS(long long a) {
if (a < 0)
return a * (-1);
else
return a;
}
int main() {
int n, m, s;
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e6 + 13;
const int MAXK = 5e6 + 13;
const long long INF = 2e9 + 7;
const long long MD = 1e9 + 7;
const long double EPS = 1e-9;
const long double PI = 3.14159265359;
bool check(long long a, long long b, long long h, long long w) {
return (a <= h && b <= w... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100 + 17;
int n;
int arr[MAXn];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
int min = 100 + 17, max = 0, jamin = 0, jamax = 0;
for (int i = n; i >= 1; i--) {
if (arr[i] < min) {
min = arr[i];
jamin = i;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
vector<long long> p;
long long a, b;
void DFS(long long x) {
if (x > b) return;
p.push_back(x);
if (x == b) {
printf("YES\n");
printf("%lld\n", (long long)p.size());
for (int i = 0; i < (int)p.size(); i++)
printf("%lld%c",... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.