solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
string a, b;
int akta;
int aktb;
vector<int> balrol;
vector<int> jobbrol;
int balhany, jobbhany;
int maximum;
string megold;
int main() {
cin >> a >> b;
while (akta < a.length()) {
while (a[akta] != b[aktb] && akta < a.length()) {
akta += 1;
}
if (akta... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
map<int, int> mp;
vector<int> A(N);
vector<int> B(N + 1);
vector<int> C(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
mp[A[i]] = i;
}
for (int i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2},
dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
struct Status {
int i, j, k;
Status() { i = j = k = 0; }
Status(int a, int b, int c) { i = a, j = b, k = c; }
};
inline bool operator<(pair<int, int> a, pair<int, int> b) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int x, y, m;
long long int myhandle_negative() {
long long int ans, temp;
if (x < 0) {
temp = -x;
ans = temp / y;
if ((temp % y) != 0) ans++;
x = (ans * y) + x;
} else {
temp = -y;
ans = temp / x;
if ((temp % y) != 0) ans++;
y... | 1 |
#include<bits/stdc++.h>
using namespace std;
int n,ti,a,b;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>ti>>a>>b;
if(!(a+b<=ti&&(ti-a-b)%2==0))
{
cout<<"No"<<endl;
return 0;
}
}
cout<<"Yes"<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int f[305][305][305];
int p[305][305];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &p[i][j]);
f[0][0][0] = p[0][0];
for (int x1 = 0; x1 < n; x1++)
for (int y1 = 0; y1 < n; y1++)
if (x1 + y1... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool visited[100005];
vector<long long> mp[100005];
long long res = 0;
long long ans = 0;
const long long U = 1e8 + 7;
void dfs(long long second) {
visited[second] = true;
ans++;
for (int i = 0; i < mp[second].size(); i++) {
res++;
if (visited[mp[second][i]] =... | 5 |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <array>
#include <set>
#include <queue>
using namespace std;
int main() {
int t;
cin >> t;
for (int _ {}; _ < t; _++) {
int n, m;
cin >> n;
vector<int> r (n);
for (in... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e2 + 10;
int a[N][N];
int stan[N][N];
int n, m;
int Num[N * N];
int p1[N * N], p2[N * N];
int L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int Max = 0;
L = 1, R = 0;
for (register int i = 1; i <= n; i++) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e6 + 5;
void compute() {
int n, m;
scanf("%d %d", &n, &m);
vector<int> v(n);
for (int i = 0; i < n; ++i) scanf("%d", &v[i]);
vector<pair<int, int> > seg(m);
vector<vector<int> > lf(n), rg(n);
for (int i = 0; i < m; ++i) {
scanf("%d%d"... | 5 |
#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... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s = "111111111";
int x;
for (int i = 0; i < 9; ++i) {
cin >> x;
x %= 2;
if (x) {
s[i] = (s[i] == '1') ? '0' : '1';
if (i % 3 > 0) s[i - 1] = (s... | 1 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
int N, M, A[1 << 17], B[1 << 17], low[1 << 17], pre[1 << 17], cnts = 0;
vector<int> G[1 << 17], Articulation;
void dfs(int pos, int prevs) {
cnts++; pre[pos] = cnts; low[pos] = cnts;
bool flag = false; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 101;
bool usable[MXN][MXN] = {};
int N, M, m[MXN][MXN] = {}, P[MXN][MXN] = {};
string names[MXN], text[MXN];
map<string, int> nS;
int solve(int message, int user) {
if (message == M - 1) return m[message][user] = 1;
m[message][user] = 0;
for (int x = 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[300010];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < (n); i++) cin >> a[i];
int ans = -1;
vector<long long> v;
for (int i = 0; i < (n); i++) {
int l = i, r = i;
while (l >= 0 && a[l] % a[i] == 0) l--;
... | 4 |
// Author - Abhishek_Chaturvedi
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define int long long
#define ld long double
#define str ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n < 3) {
cout << -1;
return 0;
}
int *a = new int[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int *f = new int[n];
int *b = new int[n];
memcpy(f, a, n * sizeof(a[0]));
sort(f, f + n);
memcpy(b, f, n ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, p, arr[100005];
long long l1, r1, pr, l2, r2, cnt1, cnt2;
pair<long long, long long> brr[100005];
double prob, amt, sum, x1, x2;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> p;
sum = 0;
for (long long i = (long long)(1); i <=... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)
int main() {
int n;
cin >> n;
ll ans = 0;
vector<int>data(n);
rep(i,0,n) cin >> data[i];
sort(data.begin(),data.end());
rep(i,0,n/2) ans -= 2*data[i];
rep(i,n/2+1,n) ans += 2*data[i]... | 0 |
#include <iostream>
using namespace std;
int my[] = {6000, 4000, 3000, 2000};
int main()
{
int n, m;
for (int i = 0; i < 4; i++){
cin >> n >> m;
cout << my[n - 1] * m << endl;
}
return (0);
} | 0 |
#include <bits/stdc++.h>
int main() {
float n, x, y, res, p;
scanf("%f%f%f", &n, &x, &y);
if (ceil((n * y) / 100) > x) {
p = ((n * y) / 100) - int((n * y) / 100);
if ((p > 0) && (p < 0.1))
res = ((n * y) / 100) + 1 - x;
else
res = ceil((n * y) / 100) - x;
printf("%.0f", res);
} else
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 103;
const int MAX_M = 103;
const int MAX_A = MAX_N + MAX_M;
const long long oo = 1000000000000000099LL;
int n, m, nA;
pair<pair<int, int>, pair<int, int> > a[MAX_A];
int b[MAX_A], p[MAX_N][MAX_N], res[MAX_N][MAX_N];
long long k;
long long f[MAX_A][MAX_A];... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> edge;
vector<int> dist;
vector<int> et;
vector<int> first;
void inedge(int n, int m) {
edge.resize(n + 1);
dist.resize(n + 1, -1);
first.resize(n + 1);
int a, b;
for (int i = 0; i < m; i++) {
cin >> a >> b;
edge[a].push_back(b);
edg... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 7;
int a[N];
int n;
int mx = -1e9;
int sum, cnt;
int mn = 1e9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] > 0 && a[i] % 2 == 1) {
mn = m... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<vector<int>> adj_list;
vector<int> leaves, parents;
int dfs(int curr, int p) {
parents[curr] = p;
if (adj_list[curr].size() == 1) return leaves[curr] = 1;
int sum = 0;
for (int c : adj_list[curr])
if (c != p) sum += dfs(c, curr);
return leaves[cu... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, p;
long long arr[1002];
long long keys[2002];
bool check(long long time) {
long long j = 0;
long long i = 0;
while (i < n) {
if (j >= k) return false;
while (j < k && abs(arr[i] - keys[j]) + abs(keys[j] - p) > time) j++;
if (j >= k) return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const long long LINF = 0x3f3f3f3f3f3f3f3f, LMOD = 1011112131415161719ll;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const int N = 1e5 + 5;
int n;
char t[N];
vector<pair<string, pair<long long, long long> > > v;
string ans;
long ... | 4 |
#include <bits/stdc++.h>
using lint = long long;
using namespace std;
using pi = pair<int, int>;
const int mod = 1e6 + 3;
lint fact[mod + 69];
lint invf[mod + 69];
lint ipow(lint x, lint p){
lint ret = 1, piv = x;
while(p){
if(p & 1) ret = ret * piv % mod;
piv = piv * piv % mod;
p >>= 1;
}
return ret % mod;... | 0 |
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 100005
using namespace std;
typedef long long int ll;
int main()
{
int n;
scanf("%d",&n);
ll ret=0;
int low=1;
for(int i=0;i<n;i++)
{
int a;
scanf("%d",&a);
if(i==0)
{
ret+=a-1;
low=2;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int s[5001];
int main()
{
int n;
while (scanf("%d", &n), n) {
for (int i = 1; i <= n; ++i) {
int a; scanf("%d", &a);
s[i] = a + s[i - 1];
}
int ma = -100000;
for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j) {
ma = max(ma, s[i] - s[j -... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, q;
int s, a, b;
vector<pair<double, double>> segs;
double f[N];
double query(int x, int y) {
double l0 = a + (double)(x - a) * (-s) / (y - s);
double r0 = b + (double)(x - b) * (-s) / (y - s);
int p;
p = upper_bound(segs.begin(), segs.e... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void read(long long &x) {
char ch = getchar();
long long f = 0;
x = 0;
while (!isdigit(ch)) {
if (ch == '-') f = 1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
if (f) x = -x;
}
const long lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct rec {
int x1, y1;
int x2, y2;
rec() {}
rec(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
bool valid() { return x1 <= x2 && y1 <= y2; }
};
rec intersect(const rec& a, const rec& b) {
rec ret;
int x1 = max(a.x1, b.x1);
int y1 = max... | 3 |
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;
int main(){
int n;
cin>>n;
vector<int> ans;
ll sum=0,k=0;
for(int i=1;;i++){
sum+=i;
k=i;
if(sum>n) break;
}
for(int i=1;i<=k;i++){
if(sum-n==i) continue;
cout<<i<<endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct Road {
long long a, b, c;
} Roads[111111];
int main(void) {
while (scanf("%d %d %d", &n, &m, &k) == 3) {
for (int i = 0; i < m; i++)
scanf("%lld %lld %lld", &Roads[i].a, &Roads[i].b, &Roads[i].c);
long long res = 0;
for (int i = 0; ... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
template <typename first>
inline first abs(const first& a) {
return a < 0 ? -a : a;
}
template <typename first>
inline first sqr(const first& a) {
return a * a;
}
const int INF = INT_MAX / 2;
const long double EPS = 1e-9;
const... | 3 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
using namespace std;
// const int dy[]={1,0,-1,-1,0,1};
// const int dx[]={0,-1,-1,0,1,1};
const int dy[]={-1,0,1,1,0,-1};
const int dx[]={0,1,1,0,-1,-1};
int main(){
int n;
cin>>n;
string tmpp;
getline(cin,tmpp);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int h;
map<int, vector<int> > adj;
bool respond(int x) {
printf("! %d\n", x);
fflush(stdout);
return true;
}
bool query(int x) {
if (adj.count(x)) return false;
printf("? %d\n", x);
fflush(stdout);
int k;
scanf("%d", &k);
if (k == 0) exit(0);
for (int i ... | 6 |
// In the name of God
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, ans[N];
vector<pair<int,int>> adj[N];
void dfs(int u, int par, int col) {
int now = 1;
for(auto v : adj[u]) {
if(v.first == par) continue;
if(now == col) now++;
ans[v.second] = now;
dfs(v.first, u, now);
n... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, n = 0, m, ss;
string s;
cin >> s;
ss = s.size();
for (int i = 0; i < ss; i++) {
if (s[i] == '(') a++;
if ((s[i] == ')') && a > 0) {
a--;
n += 2;
}
}
cout << n;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 10000000;
long long bm(long long a, long long p) {
if (p == 0) return 1;
if (p & 1) return (a * bm(a, p - 1)) % 1000000009;
long long x = bm(a, p / 2);
return (x * x) % 1000000009;
}
int main() {
long long n, m;
cin ... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll h,n;
cin>>h>>n;ll a[n],b[n];
vector<ll> dp(h+1, 1LL<<60);
for(int i=0;i<n;i++)cin>>a[i]>>b[i];
dp[0]=0;
for(int i=0;i<h;i++)
{
for(int j=0;j<n;j++)
{
ll x=i+a[j];x=min(h,x);
dp[x]=min(dp[x],dp[i]+b[j]);
... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long double lf;
typedef pair<int, int> pii;
const lf PI = 3.14159265358979;
int N;
pii P[102];
vector<pair<lf, int> > Q;
int main() {
scanf("%d", &N);
for(int i = 0; i < N; i++) {
scanf("%d %d", &P[i].first, &P[i].second);
}
cout << fixe... | 0 |
#include<queue>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
int i,j;
int a[8],c[30][256],m,n,o,u,v,x,y;
unsigned b[30][30];
double z;
priority_queue<pair<double,pair<int,int> >,vector<pair<double... | 0 |
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int dy[] = {1... | 0 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::rel_ops;
struct TN {
int k, v, p, m;
TN *l, *r;
TN(int K, int V) : k(K), v(V), p(rand()), m(V), l(0), r(0) {}
};
class Treap {
TN *root;
int getMax(TN *n) { return n ? n->m : -1; }
void update(TN *n) {
if (n) n->m = max(n->v, max(getMax(... | 5 |
#include <cstdio>
#include <algorithm>
using namespace std;
int n,nn,i,j,c,r[505*505];
pair<int,int> a[505];
int main() {
scanf("%d",&n); nn=n*n;
for (i=0; i<n; i++) {
scanf("%d",&a[i].first);
a[i].second=i+1;
}
sort(a,a+n);
for (i=0, j=1; i<n; i++) {
for (c=1; j<=nn && c<a[i].second; j++) if (r[j... | 0 |
#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 r = 1;
x = x % p;
while (y) {
if (y & 1) r = r * x % p;
y = y >> 1;
x = x * x % p;
}
return r;
}
const long long int N = 5005;
long long int n, k;
struct edge {
lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int grid[50000][5];
int last[5];
int main() {
int r, c;
scanf("%d%d", &r, &c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf("%d", &grid[i][j]);
}
}
for (int i = 0; i < r; i++) {
int curr = 0;
for (int j = 0; j < 5; j++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[300001];
int b[300001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int i, j;
int n, m;
cin >> n;
ll sum = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> m;
for (i = 0; i < m; i++) {
cin ... | 4 |
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#define NDEBUG
#endif
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=200005,INF=0X3F3F3F3F,P=1e9+7;
int n,m,f[N];
char s[N];
void sol1(){
f[1]=1;
rep(i,2,n+1)f[i]=(f[i-1]+f[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2500 + 10;
char s[maxn][maxn];
int num[maxn][maxn];
int prime[367] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
97, 101, 103, 107, 109, 113,... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
int Ans[55], TMP[55], H[1050005], n, K, Xn, Yn, X[105], Y[105], Z[105];
int now, Xt, Yt, vis[105], fac[100005];
int id[105], f[1050005];
int s[105], g[2][105][55], us[105], fa[105];
vector<int> e[105], w[105];
struct op {
int x, y, z;
} a[105];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main()
{
ll i,j;
ll n,k;
cin >> n >> k;
vector<ll> p(n);
for(i = 0;i < n;++i){
cin >> p.at(i);
}
ll cnt = 1;
vector<bool> is_sorted(n... | 0 |
#include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int main() {
int A, B, X;
cin >> A >> B >> X;
int ans = INT_MAX;
for (int i = 0; i <= A; ++i) {
for (int j = 0; j <= B; ++j) {
if (X <= 1000 * i + 500 * j) ans = min(A * i + B * j, ans);
}
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n & 1)
cout << "black\n";
else {
cout << "white\n";
cout << "1 2\n";
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long ABS(long long x) {
if (x < 0) return -x;
return x;
}
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return b / gcd(a, b) * a; }
long long n;
int main() {
cin >> n;
if (!n) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int c[200019];
int main() {
int last,x,n;
ll ans;
cin >> n;
ans=1;
last=-1;
for(int i=0; i<n; i++){
cin >> x;
if(x==last){continue;}
last=x;
ans = (ans+c[x])%1000000007;
c[x]=ans;
}
cout << ans << endl;
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 1;
for (int i = 1; i < n; i++) {
sum += i;
if (sum > n) {
sum -= n;
cout << sum << " ";
} else
cout << sum << " ";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, s, l;
int a[100005];
int Min[100005][20];
int Max[100005][20];
int dp[100005][20];
int main() {
cin >> n >> s >> l;
for (int i = 0; i < n; ++i) scanf("%d", a + i);
for (int j = 0; j < 20; ++j) {
for (int i = 0; i + (1 << j) <= n; ++i) {
if (j == 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
const int MAX_N=1<<17;
const ll INF=(1ll<<31)-1;
class Lz_segtree{
public:
int n;
ll e=0;
ll init=-1;
vector<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
typedef __int128 ll;
map <pair <ll, int>, int> ans;
inline int dfs(pair <ll, int> now) {
if (now.second == 0) return 1;
if (::ans.count(now)) return ::ans[now];
int ans = dfs(make_pair(now.first >> 1, now.second - 1)) * ((now.first & 1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char cell[152][152];
int cnt_xod[152][152];
int cnt_W[152][152];
int main() {
cin >> n >> m;
int nuclear = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> cell[i][j];
if (cell[i][j] == 'W') ++nuclear;
cnt_W[i][j]... | 4 |
#include<iostream>
long long int a[31];
int main(){
int n;
a[0] = 1, a[1] = 1, a[2] = 2;
for (int i = 3; i <= 30; ++i){
a[i] = a[i - 1] + a[i - 2] + a[i - 3];
}
while (std::cin >> n ,n){
std::cout << (a[n]/3650)+1 << std::endl;
}
} | 0 |
#include <bits/stdc++.h>
int main() {
int n, i, j, k;
char a[1000];
while (~scanf("%d", &n)) {
getchar();
gets(a);
int m = 0;
for (i = 0; i < n; m++, i += m) printf("%c", a[i]);
printf("\n");
}
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
int dp[301][301],f[301][301];
string ch(string s,string t){
memset(dp,0,sizeof(dp));
memset(f,0,sizeof(f));
s="@"+s,t="@"+t;
int m=s.size(),n=t.size();
for(int i=1;i<m;i++)
for(int j=1;j<n;j++){
if(s[i]==t[j]... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-10, pi = acos(-1);
const int N = 2e6 + 10, M = 1e6 + 10, ha = 131, INF = 0x3f3f3f3f,
mod = 998244353;
int m, n, k;
int a[N][2];
int b[N][2];
int f1, f2;
int xx, yy;
map<pair<int, int>, int> mp;
long long s[N];
int flag[2];
void add(int x... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int N = 200010;
struct edge {
int v, nxt;
} g[N << 1];
int tot = 0, head[N];
inline void add(int u, int v) {
g[++tot] = edge{v, head[u]};
head[u] = tot;
}
int n, q, p[N], fa[N], dfn[N << 2], dep[N], A[N], cnt = 0, bg[N],
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); }
int main() {
long double x1, y1, x2, y2, x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
lo... | 2 |
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=100005;
const int logn=20;
int n,q,l;
int dep[maxn];
int up[maxn][logn];
vector<int>G[maxn];
void dfs(int u,int p) {
dep[u]=dep[p]+1;
up[u][0]=p;
for (int i=1;i<=l;i++) up[u][i]=up[up[u][i-1]][i-1];
for (int v:G[u])
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int M = 5005;
const int N = 505;
const int INF = 0x3f3f3f3f;
int d, s;
bool vis[N][M];
int pre[N][M][3];
queue<int> Qx, Qy;
void bfs() {
vis[0][0] = 1;
Qx.push(0);
Qy.push(0);
while (!Qx.empty()) {
int x = Qx.front();
Qx.pop();
int y = Qy.front();
... | 1 |
//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//11:48
using namespace std;
typedef long long ll;
typedef pair<int, int> pii... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int si = 0, n, x, sp = 0, nri = 0, mn = 1000;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x % 2 == 0) {
sp += x;
} else {
nri++;
si += x;
if (x < mn) mn = x;
}
}
if (nri == 0) {
cout << 0;
ret... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)1e5 + 15;
bool isAns = 1;
int n, m;
vector<vector<int>> gr;
vector<int> a, b;
void in() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
gr.resize(n + 5);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
gr[a]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n & 1) {
cout << -((n + 1) >> 1);
} else {
cout << (n >> 1);
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5001, MOD = 1e9 + 7;
int Pre[MAXN][2];
int get(int l, int r, int cur) {
return (Pre[r][cur] - Pre[l - 1][cur] + MOD) % MOD;
}
int main() {
int N, k, a, b, ans = 0;
cin >> N >> a >> b >> k;
Pre[a][0] = 1;
for (int K = 1; K <= k; K++) {
int nxt ... | 3 |
#include<bits/stdc++.h>
using namespace std;
long long a[100001], n, k, sum, p, m, d;
int main(){
cin >> n;
m = (n * (n + 1)) / 2;
for(int i = 0; i < n; i++) cin >> a[i], sum += a[i];
if(sum % m){
cout << "NO";
return 0;
}
k = sum / m;
for(int i = 0; i < n; i++){
d = a[(i + 1) % n] - a[i];
if(k < d || ... | 0 |
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int const MAXN=15;
int n;
vector<pair<int,int>> v[MAXN];
bitset<MAXN> b;
int ans=0;
void check(){
for(int i=0;i<n;i++){
if(b[i]==0)
continue;
for(auto p:v[i]){
if(b[p.first]!=p.second)
return;
}
}
ans=ma... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long OO = 2e18;
const double pi = 2 * acos(0.0);
bool isprime(long long int a) {
if (a == 1) {
return false;
}
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
bool iscoprime(int a, int b) {
int i... | 3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> tab(n);
for (long long i = 0; i < n; i++) {
cin >> tab[i];
}
if (k == 1) {
sort(tab.begin(), tab.end());
cout << tab[0] << endl;
} else if... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3fffffff;
const long long mod = 1000000007;
const int maxn = 3e5 + 100;
int sa[maxn];
int t1[maxn], t2[maxn], c[maxn];
int rk[maxn], height[maxn];
void build_sa(int s[], int n, int m) {
int i, j, p, *x = t1, *y = t2;
for (i = 0; i < m; i++) c[i] = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int hs[30], ht[30];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
memset(hs, 0, sizeof(hs));
memset(ht, 0, sizeof(ht));
string s, t;
cin >> s >> t;
for (int i = 0; i < n; ++i) {
hs[s[i] - 'a']++;
ht[... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int ans;
int a[5][105][105];
int b[205][205];
int main() {
cin >> n;
ans = n * n * 4;
int c[5] = {0, 1, 2, 3, 4};
for (int i = 1; i <= 4; i++)
for (int j = 1; j <= n; j++) {
string s;
cin >> s;
for (int k = 1; k <= n; k++) a[i][j][k] = s... | 3 |
#include <bits/stdc++.h>
using namespace std;
int p[200010], bl[200010], fl[200010], fr[200010], tg[200010 / 223 + 5];
long long sc[200010 / 223 + 5];
void reslv(int u) {
sc[u] = 0;
for (int i = fl[u]; i <= fr[u]; i++) p[i] = max(p[i], tg[u]), sc[u] += p[i];
tg[u] = 0;
}
void slv(int u, int v) {
if (v <= p[fr[u... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 10;
string s[2003];
string name[10];
long long dp[2005][12];
long long via[2005][2005];
long long ans[2005], flag, n, k;
map<string, long long> mp;
void dfs(long long pos, long long sum) {
if (flag == 1 || sum < 0) return;
if (pos >= n) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M = 2000000000;
struct ST
{
int n;
vector<int> lazy;
vector<int> tree;
ST(int n1)
{
n = n1;
lazy.assign(4 * n, 0);
tree.assign(4 * n, 0);
}
void clean()
{
lazy.assign(4 * n,... | 5 |
#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
const double PI = acos((double)-1);
int ts, ts2, ts3, ts4;
int h, l;
long long gcd(long long x, long long y) {
long long t;
for (; y != 0;) {
t = x % y;
x = y;
y = t;
}
return x;
}
double sqr(double x) { return x * x; }
template ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n < m) {
if (n % 2 == 0) {
cout << "Malvika";
} else {
cout << "Akshat";
}
} else {
if (m % 2 == 0) {
cout << "Malvika";
} else {
cout << "Akshat";
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long bigmod(long long p, long long e, long long M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int main() {
int l, p, q;
scanf("%d%d%d", &l, &p, &q);
printf("%.10lf\n", l * 1.0 / (p + q) * 1.0 * p);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long INF=99999999999;
long long n,k[200005],l[200005],sum,mon=INF;
int main(){
cin>>n;
for(int i=0;i<n;++i){
cin>>k[i]>>l[i];
sum+=k[i];
if(k[i]>l[i]){mon=min(mon,l[i]);}
}
if(mon==INF){
cout<<0<<endl;
return 0;
}
cout<<sum-mon<<endl;
}... | 0 |
#include<iostream>
#include<map>
#define int long long
using namespace std;
map<char, int>m;
signed main() {
m['('] = 1; m[')'] = -1;
int n, cnt = 0; cin >> n;
bool flag = 1;
for (int i = 0; i < n; i++) {
char c; int p; cin >> c >> p;
cnt += m[c] * p;
if (cnt < 0)flag = 0;
}
if (cnt != 0)flag = 0;
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
void solve() {
int n;
cin >> n;
string s;
cin >> s... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, l, j, t[5010][5010], b[5010], maxx;
char s[5010];
inline int max(int a, int b) {
if (a > b)
return a;
else
return b;
}
int main() {
scanf("%d %d", &n, &m);
gets(s);
for (i = 1; i <= n; i++) {
gets(s + 1);
for (j = 1; j <= m; j++)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 3e5 + 1;
struct TQuery {
int id, L, R;
};
int N, res[MaxN];
int IT[MaxN << 2], F[MaxN];
TQuery Q[MaxN];
void Enter() {
int x, h;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> x >> h;
Q[i].id = i;
Q[i].L = x;
Q[i].R = x + h - 1;
}... | 5 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct vect{
int x, y;
};
bool equals(vector< vect > v1, vector< vect > v2 ){
bool flg[8];
bool ret = false;
if( v1.size() != v2.size() ) return false;
for(int i = 0; i < 8; i++)
flg[i] = true;
//0,90,180,27... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int N, X, count;
cin >> N >> X;
if (N == 1 || N == 2) {
cout << "1";
} else {
count = N - 2;
if (count % X == 0) {
cout << ((N - 2) / X) + 1;
} else {
cout << ((N - 2) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int64_t getMid(int64_t s, int64_t e) { return s + (e - s) / 2; }
bool compareTuple(tuple<int64_t, int64_t, int> a,
tuple<int64_t, int64_t, int> b) {
return get<1>(a) > get<1>(b);
}
int64_t constructSTUtil(int64_t arr[], int64_t ss, int64_t se, int64_t *s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, r, x, y, k;
cin >> l >> r >> x >> y >> k;
if (l / k > y) {
cout << "NO";
return 0;
}
if (r / k < x) {
cout << "NO";
return 0;
}
while (x + 1 < y) {
long long mid = (x + y) / 2;
if (mid * k > r) {
y = mid;... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.