solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long ll;
const int N = 5e5 + 7;
const int inf = 0x3f3f3f3f;
int a[N], dp[N];
int l[N], r[N], c[N];
int main(void){
IOS;
int n; cin >> n;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 10;
const long long mod = 998244353;
double eps = 1e-10;
void in(long long &x) {
x = 0;
char c = getchar();
long long y = 1;
while (c < '0' || c > '9') {
if (c == '-') y = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
... | 1 |
#include <bits/stdc++.h>
const int N=200005,mu=1e9+7,inv2=(mu+1)/2;
int s[N],a[N],n,S,T[N],c[N],ans,d[N],zero[N];
void reduce(int &x) { x+=x>>31μ }
int ksm(int x,int y){
int ans=1;
for (;y;y>>=1,x=x*1ll*x%mu)
if (y&1) ans=ans*1ll*x%mu;
return ans;
}
int lowbit(int x){
return x&(-x);
}
void upd(int x,int y){
w... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int ci[] = {1, 0, -1, 0};
const int cj[] = {0, -1, 0, 1};
int n, m;
char a[505][505];
int b[505][505];
int id[505][505], _id, counter[250005];
bool gone[505][505];
bool inside(int i, int j) { return min(i, j) >= 1 && max(i, j) <= n; }
void go(int i, int j) {
if (gon... | 3 |
#include <bits/stdc++.h>
using namespace std;
int get() {
char ch;
while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
;
if (ch == '-') {
int s = 0;
while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
return -s;
}
int s = ch - '0';
while (ch = getchar(), ch >= '0' &... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
long long int n;
cin >> n;
long long int A[n], c[n];
for (long long int i = 0; i < n; i++) cin >> A[i];
for (long long int i = 0; i < n; i++) cin >> c[i];
long long int ans ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, a, b;
double smalst, angle, bb;
cin >> n >> a;
if (n == 3) {
cout << 2 << ' ' << 1 << ' ' << 3;
return 0;
}
angle = 180 - (double)360 / n;
smalst = angle / (n - 2);
... | 2 |
#include<stdio.h>
#include<algorithm>
using namespace std;
int b[41000];
int c[41000];
int d[41000];
int e[41000];
struct wolf{
int p,q;
wolf(){}
wolf(int A,int B){
p=A;q=B;
}
};
inline bool operator<(const wolf&a,const wolf&b){
return (long long)a.p*b.q<(long long)a.q*b.p;
}
wolf t[41000];
int main(){
int a;sc... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int x[maxn];
int r[maxn];
int q[maxn];
int n, k;
int cid = 0;
int lpos[maxn], rpos[maxn];
int* tree[maxn];
vector<int> pos[maxn];
set<int> ayy;
map<int, int> lmao;
int lwb[maxn];
int pps[maxn];
int tot[maxn];
void add(int* t, int len, int pos, int ... | 1 |
#include <iostream>
#include <string>
using namespace std;
int main(void){
string s;
int x[26] = {};
while(getline(cin,s) ){
for(int i = 0;i < s.size();i++){
char c = s.at(i);
c = tolower(c);
x[c - 'a']++;
}
}
for(int i = 0;i < 26;i++){
cout << char(i+'a') <<" : "<< x[i] << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
bool odd(int n) { return n % 2 == 1; }
void ans(int k) {
if (k == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * f;
}
long long F[20][30000... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mp(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) r... | 3 |
#include <stdio.h>
#include <algorithm>
using namespace std;
int D[303][303][155];
char S[303]; int K;
int main()
{
scanf("%s %d", S+1,&K);
int N = 0;
while (S[N + 1]) N++;
if (2 * K > N) {
printf("%d\n" , N);
return 0;
}
for (int i = 1; i <= N; i++) {
for (int j = N; j > i; j--) {
for (int k = 0; k <=... | 0 |
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int a, b, c;
cin >> a >> b >> c;
if(a > b && a > c){
cout << "A" << endl;
}
else if(b > a && b > c){
cout << "B" << endl;
}
else{
cout << "C" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=n-1;i>=0;i--){
if(i>0){
cout<<a[i]<<" ";
}
}
cout<<a[0]<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, s;
int ar[300005];
vector<int> pr;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> s;
int free = 0;
for (int i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] && i != (s - 1))
pr.push_back(ar[i]);
els... | 3 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
time_... | 3 |
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{ ll n,m=0,i,la=0;
cin>>n;
for(i=1;i<pow(10,9);i++)
{ m=m+i;la++;
if(m>=n)break;
}
cout<<la<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
while (~scanf("%d%d", &n, &m)) {
vector<int> diff(n);
for (int i = 0; i < n; i++) cin >> diff[i];
vector<int> ans;
for (int i = 1; i < n; i++) {
ans.push_back(diff[i - 1] - diff[i]);
}
sort(ans.begin(), ans.end());
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
long long r=0,g=0,b=0;
for(int i=0;i<n;i++)
{
if(s[i]=='R')
r++;
else if(s[i]=='B')
b++;
else g++;
}
long long cnt=0;
for(int i=0;i<n-2;i++)
{
for(int j=i+1;j<n-1;j++)
{
if(s[i]!=s[j])
{... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<long long int> v;
long long int temp;
for (long long int i = 0; i < n; i++) {
cin >> temp;
v.push_back(temp);
}
sort(v.begin(), v.end(), greater<int>());
double ans = v[0];
double s = 0.0;
for (lon... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long c[5005][5005];
long long sr[5005], sc[5005];
const long long inv = numeric_limits<long long>::max();
int main() {
scanf("%d%d", &n, &m);
for (int i = 2; i <= 4 * n; i += 4)
for (int j = 2; j <= 4 * m; j += 4) cin >> c[i][j];
for (int i = 2; i <... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d,e,f,answ=1,anss=0;
cin>>a>>b>>c>>d>>e>>f;
for(int i=0;i*100*a<=f;i++){
for(int j=0;j*100*b+i*100*a<=f;j++){
int w=j*100*b+i*100*a;
for(int k=0;k*c+w<=f;k++){
for(int l=0;w+k*c+l*d<=f;l++){
... | 0 |
#include <bits/stdc++.h>
int main() {
int n, m, i, j, a[20001], count = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= 2 * m * n; i++) {
scanf("%d", &a[i]);
if (i % 2 == 0) {
if (a[i - 1] == 1 || a[i] == 1) count++;
}
}
printf("%d", count);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using lol = long long int;
const lol mod1 = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
if (min(n, m) >= 4) {
cout << "-1";
return 0;
}
if (min(n, m) == 1) {
cout << "0";
return 0;
}
vecto... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
cin>>A>>B;
int sum=0;
for(int i=A;i<=B;i++){
if(i/10000==i%10&&i%10000/1000==i%100/10){
sum++;
}
}
cout<<sum<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
string str[500005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> str[i];
}
for (int i = n - 2; i >= 0; i--) {
int k = 0;
while (1) {
if (k == str[i].size() || str[i][k] < ... | 4 |
#include <bits/stdc++.h>
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;
}
using namespace std;
long long power(long long a, long long b) {
long long re... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
int h, w;
int a[2000][2000];
int b[2000][2000];
int mark[2000][2000];
int cnt;
int anch[6][6] = {{1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1,... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 100;
int n;
int a[max_n];
int b[max_n];
int res[max_n];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 2; i <= n; ++i) {
if (a[i] > a[i - 1])
b[i - 1] = b[i] = 1;
else if (a[i] < a[i - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a[1005], b[1005], i, s1, s2;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
s1 = a[1];
for (i = 2; i <= n; i++) s1 = a[i] | s1;
for (i = 1; i <= n; i++) cin >> b[i];
s2 = b[1];
for (i = 2; i <= n; i++) s2 = b[i] | s2;
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> m;
int main() {
long long t, ai, bi, dr = 1;
cin >> t;
vector<pair<long long, long long>> v(t);
for (int i = 0; i < t; i++) {
cin >> ai >> bi;
v[i] = {ai, bi};
}
m[{0, 0}] = 1;
dr += min(v[0].first, v[0].secon... | 2 |
#include <cstdio>
char str[200010];
int main() {
scanf("%s", str);
for (int i = 0; str[i]; ++i)
if (str[i] == '?')
str[i] = 'D';
puts(str);
return 0;
}
| 0 |
#include <iostream>
#include <cassert>
using namespace std;
#define N 8
#define FREE -1
#define NOT_FREE 1
int row[N], col[N], dpos[2*N-1], dneg[2*N-1];
bool X[N][N];
void initialize(){
for(int i = 0;i < N; i++){
row[i] = FREE;
col[i] = FREE;
}
for(int i = 0; i < 2*N-1;i++){
dpos[i] = FREE;
d... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a, b[100100], p[100100];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m >> a;
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 1; i <= m; i++) cin >> p[i];
sort(b + 1, b + n + 1);
reverse(b + ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double kEps = 1E-8, kPi = acos(-1.0);
const int kMaxN = 10000, kMaxM = 100000;
int n, m, seq[kMaxM], s;
double v, agl[kMaxN];
pair<double, double> wall[kMaxM];
double need[kMaxM];
inline int sgn(double x) {
if (fabs(x) < kEps) return 0;
if (x > 0.0) return 1;
re... | 5 |
#include <bits/stdc++.h>
using namespace std;
int M = 998244353;
int main() {
int n;
long long sum = 0;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
for (int i = 0; i < n / 2; i++) {
sum += (v[i] + v[n - i - 1]) * (v[... | 3 |
#include <cstdio>
#include <cstring>
const int MAX_N = 100000;
const int MAX_Q = 100000;
//输入
int N, Q;
int par[MAX_N + 1]; //父结点
bool marked[MAX_N + 1]; //标记结点
void init(){
//初始化
par[1] = 1;
memset(marked, 0, sizeof(marked));
marked[1] = true;
for(int i = 2; i <= N; i +... | 0 |
#include <bits/stdc++.h>
using namespace std;
long double eps = 0.000000001;
struct Mn {
long double num;
vector<long double> v;
};
Mn del(Mn a, Mn b) {
long double diff = a.num - b.num + 1;
for (long double i = 0; i < diff; i++) {
long double degree = a.num - i;
long double raz = degree - b.num;
lo... | 2 |
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
const int MAXN = 40001;
const int INF = 1<<28;
int N;
int X[MAXN], Y[MAXN];
bool vis[MAXN];
vector<pair<pair<int,int>,int> > xy, yx;
int dfs(int v) {
const int &x = X[v];
const int &y = Y[v];
vis[v] = true;
int res ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 10000 + 10;
int B[maxn], E[maxn];
multiset<int> A[2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int j = 0, k; j < 2; ++j) {
cin >> k;
for (int i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int A[30];
vector<int> mov;
void change(string &c) {
for (int i = 0; i < mov.size(); ++i) {
string temp2 = "";
for (int j = 0; j < c.size() - mov[i]; ++j) {
temp2 += c[j];
}
string temp = "";
for (int k = 0; k < mov[i]; ++k) {
temp += c[c.s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int where[maxn], to[maxn], can[maxn], a[maxn], b[maxn];
int main(){
where[0] = 1;
int n, q; cin >> n >> q;
for(int i = 1; i <= q; i++) cin >> a[i] >> b[i];
for(int i = 1; i <= q; i++){
where[i] = where[i - 1];
if(where[i] == a[i] || where[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
#define _int64 long long
_int64 a[60];
int main()
{
_int64 i,j,n,tmp,ans,b1;
scanf("%lld",&n);
for (i=0;i<n;i++)
scanf("%lld",&a[i]);
ans=0;
b1=1;
while (b1==1)
{
b1=0;
for (i=0;i<n;i++)
if (a[i]>=n)
{
b1=1;
tmp=a[... | 0 |
// Problem: E1. Square-free division (easy version)
// Contest: Codeforces - Codeforces Round #708 (Div. 2)
// URL: https://codeforces.com/contest/1497/problem/E1
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)
/* ID: vqt
LANG: C++14
PROB: namenum
*/
// #pragma GCC op... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Pt {
long long x, y;
} pt[101000], m;
Pt operator+(Pt a, Pt b) {
a.x += 2 * b.x;
a.y += 2 * b.y;
return a;
}
Pt operator-(Pt a, Pt b) {
a.x -= 2 * b.x;
a.y -= 2 * b.y;
return a;
}
int ab(int b) {
if (b < 0) return -b;
return b;
}
int main() {
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int c = 0;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (a != b) {
c = 1;
}
}
if (c == 0) {
cout << "Poor Alex";
} else {
cout << "Happy Alex";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main() {
int n,m,mod=256;
cin >> n;
map<string,P> ma;
for(int i=0; i<n; i++) {
string s;
P p;
cin >> s >> p.first >> p.second;
ma[s]=p;
}
queue<vector<int> > que;
cin >> m;
for(int i=0; i<m; i++) {
string s;
... | 0 |
#include<stdio.h>
int main(void){
int n;
int sum;
int x[5];
int i, j;
int max[100], min[100];
for(j=0; j<100; j++){
min[j]=500;
max[j]=0;
scanf("%d",&n);
if(n==0){
break;
}
for(i=0; i<n; i++){
scanf("%d%d%d%d%d",&x[0],&x[1],&x[2],&x[3],&x[4]);
sum=x[0]+x[1]+x[2]+x[3]+x[4];
if(min[j] >= ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long logN = 20;
const long long M = 998244353;
const long long INF = 1e12;
const long long N = 3005;
string s, t;
long long dp[N][N];
void solve() {
cin >> s >> t;
long long n = s.length();
long long m = t.length();
for (long long i = 0; i < n - m; i++) t... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
map<long long, pair<long long, long long>> m1;
vector<long long> v2;
long long i, j;
v2.push_back(4);
v2.push_back(8);
v2.push_back(15);
v2.push_back(16);
v2.push_back(23);
... | 2 |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
char g[500][500];
int cur = 0,ans[500][500];
void add(int cl,int cr,int rl... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v[150010];
long long int visit[150001];
long long int tvisit[150001];
vector<long long int> ans;
void dfs(long long int s) {
visit[s] = 1;
ans.push_back(s);
for (long long int i = 0; i < v[s].size(); i++) {
if (!visit[v[s][i]]) {
dfs(v[... | 2 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
using namespace std;
type... | 0 |
#include <bits/stdc++.h>
using namespace std;
char str[200005];
int a[200005];
int n;
int cmp(int a, int b) { return a > b; }
void change(int l, int r) {
for (int i = l; i <= r; i++) swap(str[i], str[n - i + 1]);
}
int main() {
scanf("%s", &str[1]);
int m;
n = strlen(&str[1]);
scanf("%d", &m);
for (int i = ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
double a, b;
double ans = 1e26;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a >> b;
ans = min(ans, (double)(m)*a / b);
}
cout << fixed << setprecision(6);
cout << ans << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
const int MOD = 998244353;
int n, k;
char s[N];
vector<int> ones;
int dp[N][N][N];
int f(int x, int use, int sum) {
if (use > k) return 0;
if (x < 0) return sum == 0;
if (~dp[x][use][sum]) return dp[x][use][sum];
int ret = f(x-1, use, sum);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 9, mod = 1e9 + 7;
int arr[N];
bool occured[N];
long long dp[N][N];
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
if (arr[i] > 0) {
occured[arr[i]]++;
}
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int k, i, j, n, x, sze;
cin >> n;
string s, t, r, ans, ch;
s = to_string(n);
sze = s.size();
r = s;
for (i = 1; i <= sze; i++) {
if (i <= (sze / 2)) {
t += '4';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> sz[2][4][31];
int mark[2][31] = {0};
void go(long long si, long long sj, long long st, long long en, int level,
int f) {
if (si > en || sj < st) return;
if (si >= st && sj <= en) {
for (int i = level; i < 30; ++i) {
mark[f][i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int u, step;
Node(int u, int step) : u(u), step(step) {}
bool operator>(const Node& rhs) const { return step > rhs.step; }
};
const int N = 500010;
int n;
vector<tuple<int, int, int>> rg[N];
vector<int> hl[N][2], hr[N][2], dis[N][2];
vector<vector<tuple<... | 6 |
#include<iostream>
using namespace std;
int main(){
int E,Y;
cin>>E>>Y;
if(E==0){
if((1868<=Y)&&(Y<=1911))
cout<<'M'<<Y%1867<<endl;
if((1912<=Y)&&(Y<=1925))
cout<<'T'<<Y%1911<<endl;
if((1926<=Y)&&(Y<=1988))
cout<<'S'<<Y%1925<<endl;
if((1989<=Y)&&(Y<=2016))
cout<<'H'<<Y%1988... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void Main();
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(10);
Main();
}
int n, m;
vector<int> a, x, y, cnt;
vector<vector<int>> want;
void Main() {
cin >> n >> m;
a.resize(n);
for (a... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
__int128 gcd(__int128 a, __int128 b) {
if (a < 0) a = -a;
if (b < 0) b = -b;
if (min(a, b) == 0) return a + b;
return gcd(b, a % b);
}
struct frac {
__int128 z, n;
frac(__int128 z = 1, __int128 n = 1) {
this->z = z;
this->n = n;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
long long binpow(long long a, long long b);
long long modmul(long long a, long long b, long long m);
void solve() {
long long n, x, ans = 0;
cin >> n;
multiset<long long> st;
for (long long i = 0; i < n; i++) {
cin >> x;
st... | 3 |
#include <iostream>
#include <cmath>
using namespace std;
int main(){
long long n;
cin>>n;
n++;
n=log2(n);
cout<<n<<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
const double EPS = 1e-24;
const long long int MOD = 1000000007ll;
const double PI = 3.14159265359;
int INF = 2147483645;
long long int INFINF = 9223372036854775807;
template <class T>
T Max2(T a, T b) {
return a < b ? b : a;
}
template <class T>
T Min2(T a, T b) {
return a < b ? a : b;
}
te... | 2 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int mod=1e9+7;
int p[200000],m[200000];
signed main(){
int n,x,y;
cin>>n;
for(int i=0;i<n;i++){
cin>>x>>y;
p[i]=x+y;
m[i]=x-y;
}
sort(p,p+n);
sort(m,m+n);
cout<<max(p[n-1]-p[0],m[n-1]-m[0])<<... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, m;
int stk[100005][2];
int bak[100005][2];
vector<pair<int, int> > v;
int top = 0;
int main() {
cin >> n >> k >> m;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (!top || stk[top][0] != x) {
stk[++top][0] = x;
stk[top][1] = 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000 + 10;
const int inf = 522133279;
const int mod = 1000000007;
int n, m, minc, maxc;
int a[110];
int main() {
cin >> n >> m >> minc >> maxc;
for (int i = 0; i < m; i++) cin >> a[i];
sort(a, a + m);
if (a[0] < minc || a[m - 1] > maxc)
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 2048;
int main() {
long long n, m, x1, x2, y1, y2, l1, l2, r1, r2, d1, d2, u1, u2, l, r, d, u,
ans, a1, a2, b1, b2;
int _;
scanf("%d", &_);
while (_--) {
cin >> n >> m >> x1 >> y1 >> x2 >> y2;
if (x1 > x2... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string init;
bool running = false;
bool changes = false;
cin >> init;
for (long i = 0; i < init.size(); i++) {
if (running) {
if (init[i] == 'a')
break;
else {
init[i]--;
changes = true;
}
} else {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[20];
int main() {
int n, b[20];
cin >> n;
for (int i = 0; i < n; i++) cin >> b[i];
int kol = 1;
for (int i = 0; i < n; i++) kol *= 2;
for (int i = 0; i < kol; i++) {
int sum = 0;
a[n - 1]++;
for (int j = n - 1; j > 0; j--) {
a[j - 1] = a[... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
bitset<7001> die[100001];
bitset<7001> fact[7001];
bitset<7001> mulp[7001];
int main() {
int n, q, i, j, a, b, c;
scanf("%d%d", &n, &q);
for (i = 1; i <= 7000; i++)
for (j = 1; j <= 7000; j++)
if (i % j == 0) fact[i][j] = 1;
mulp[1... | 6 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
map<long long int, int> soinnsuu(long long int a) {
map<long long int, int> ans;
for (long long int i = 2; i * i <= a; ++i) {
if (i > a) break;
while (a % i == 0) {
ans[i]++;
a /= i;
}
}
if (a != 1) ans[a]++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
int T;
int mai... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string str;
while (n--) cin >> str;
int i = 0, cn = str[0] == 'B';
for (i = 1; i < m; i++) {
if (str[i] == 'B' && str[i - 1] == '.') cn++;
}
cout << cn << endl;
}
| 4 |
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
char a[55][55];
int main() {
int n, m, i, j, k, flag = 0;
cin >> n >> m;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) cin >> a[i][j];
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i][j] == '#') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int p, q, l, r, i, j, a, b, s = 0, c, k, d, q1, w1;
bool flag = false;
vector<pair<int, int> > v, v2;
scanf("%d%d%d%d", &p, &q, &l, &r);
for (i = 0; i < p; i++) {
scanf("%d%d", &a, &b);
v.push_back(make_pair(a, b));
}
for (i = 0; i < q; i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1 << 10;
int T;
int V;
vector<int> G[MAXV];
bool mark[MAXV];
int label[MAXV];
int K1, K2;
int x[MAXV];
int y[MAXV];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> V;
for (int i = 0; i < V; ++i) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4004;
int arr[N][N];
int cum[N][N];
int n, k;
int val[N][N];
int memo[3][N];
int getcum(int f, int t) {
return cum[t][t] - cum[t][f - 1] - cum[f - 1][t] + cum[f - 1][f - 1];
}
void solve(bool l, int s, int e, int f, int t) {
if (s > e) return;
int mid = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
namespace JCKing {
#define isdigit(ch) (ch >= '0' && ch <= '9')
typedef long long LL; typedef double db;
const int INF = 1e9 + 7;
#define getc getchar
#define file freopen
#define filein(s) freopen(s".in", "r", stdin)
#define fileout(s) freopen(s".out", "w", stdout)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int b = 0;
cin >> b;
if (b == 1) {
ans = 1;
}
}
if (ans == 1) {
cout << "HARD";
} else {
cout << "EASY";
}
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,x,res=0;
cin>>n>>k;
for(int i=0;i<n;i++) {cin>>x;if(x>=k) res++;}
cout<<res;
return 0;
} | 0 |
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)
using names... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
int maxi = 0, cant = 1, cont;
int mat[MAX];
stack<int> s;
string curr;
int main() {
cin >> curr;
for (int i = 0; i < curr.size(); i++) {
if (curr[i] == '(')
s.push(i);
else if (!s.empty())
mat[i] = -1, mat[s.top()] = 1, s.pop... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
if (n > m) swap(n, m);
if (n == 1)
printf("%d\n", m);
else if (n == 2) {
m--;
int t = (m / 4 + 1) * 2;
if (m % 4 == 0) t--;
printf("%d\n", 2 * t);
} else
printf("%d\n", n * m - n * m / 2);
r... | 2 |
#include <bits/stdc++.h>
inline long long inL() {
long long x;
scanf("%I64d", &x);
return x;
}
using namespace std;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const int N = 509;
bool dp[N][N][N];
int c[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
n = in();
k = in(... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a[200010], b, f[500010],
er[500010], q, x, y, s, o;
bool tk[500010];
vector<long long> fc;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int inst, day;
cin >> inst >> day;
pair<int, int> days[inst];
int cnt = 0;
for (cnt; cnt < inst; cnt++) cin >> days[cnt].first, days[cnt].second = cnt;
sort(days, days + inst);
int sum = 0;
for (cnt = 0; cnt < inst; cnt++) {
if (sum + days[c... | 1 |
#include <bits/stdc++.h>
int main(void) {
int n;
std::cin >> n;
std::map<int, int> a;
int cur_answer = 0;
int cur_index = -1;
for (int i = 0; i < n; ++i) {
int cur;
std::cin >> cur;
++a[cur];
if (a[cur] > cur_answer) {
cur_answer = a[cur];
cur_index = cur;
}
}
std::cout <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned int n;
cin >> n;
vector<tuple<int, int, char, long long, string>> tpl;
for (int i = 0; i < n; ++i) {
int v;
int w;
char t;
long long d;
string s;
cin >> v >> w >> t >> d >> s;
t... | 0 |
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::nu... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1000050], b[1000050], c[1000050], n, k, m, t;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
a[n] = 0;
memset(c, -1, sizeof(c));
m = 0;
b[m] = 0;
c[0] = 0;
t = 0;
for (int i = 1; i <= n; i++)
if (a[i] < a[b[m]... | 6 |
#include <iostream>
#include <unordered_map>
#include <string>
using namespace std;
int n,i,x;
int s[52];
string num,k;
unordered_map <string, int> m;
int main()
{
cin>>n;
for(i=1;i<=n;i++)
{
cin>>num>>x;
s[i]=s[i-1]+x;
m[num]=i;
}
cin>>k;
cout<<s[n]-s[m[k]];
return 0... | 0 |
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define MAX 20
#define INF 1e9
vector<int> vec,v[MAX],a[MAX];
void init(int N){
vec.clear();
for(int i = 0 ; i < MAX ; i++){
v[i].clear();
}
for(int i = 1 ; i < 1<<N ; i++){
int idx = __builtin_popcount(i);
v[idx-1].... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b, long long &x, long long &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long x1, y1;
long long d = gcd(b % a, a, x1, y1);
x = y1 - x1 * (b / a);
y = x1;
return d;
}
bool find_any_solution(long long a, long... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.