solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int solve(int n) {
int cnt = 0;
for (int i = 1;i <= n / 2; i++) {
int m = 0;
int j = i;
while(m < n) m += j++;
if (m == n) cnt++;
}
return cnt;
}
int main() {
int n;
while(cin >> n, n) {
cout << solve(n) << endl;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll e=0,f=0;
vector<int> G[200001];
map<P,ll> A;
void dfs(int x,int y,int z=-1){
if(x==y){
f=1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string str;
cin >> str;
int c1 = 0, c2 = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '0') {
if (c1)
printf("3 1\n"), c1--;
else
printf("1 1\n"), c1++;
} else {
if (c2)
printf("4 1\n"), c2... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int32_t main() {
string s;
cin >> s;
long long n = s.size();
map<long long, vector<long long> > h;
for (long long i = 0; i < n - 1; i++) {
if (s[i] == 'A' && s[i + 1] == 'B') {
h[0].push_back(i);
}
if (s[i] == 'B... | 1 |
#include <iostream>
using namespace std;
char conv[128];
void make() {
for(int i = 0; i < 128; ++i) conv[i] = i;
}
int main() {
int n, m;
while((cin >> n) && n) {
make();
for(int i = 0; i < n; ++i) {
char a, b;
cin >> a >> b;
conv[a] = b;
}
cin >> m;
for(int i = 0; i < m; ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
T gcd(T a, T b) {
return ((b == 0) ? a : gcd(b, a % b));
}
bool cmp(pair<string, int> a, pair<string, int> b) {
return a.first.size() < b.first.size();
}
int main() {
ios_base::sync_with_stdio(fa... | 3 |
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
using Double = long double;
signed main(){
Int h,w;
cin>>w>>h;
vector<string> s(h);
for(Int i=0;i<h;i++) cin>>s[i];
vector<vector<Int> > dg(h,vector<Int>(w,-1)),ds=dg;
using T = pair<Int,int>;
queue<T> qg,qs;
for(Int i=0;i<h;i++){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, x;
cin >> n >> x;
int odd = 0, even = 0;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
(a & 1 ? odd : even) += 1;
}
bool ok = false;
for (int i = 1; i <= x; i += 2) ok |= (odd >= i && even >= x - i);
cout << (ok ? "Yes\n" :... | 1 |
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[50],b[50];
int A[51],B[51];
int dp[51][51][51][51][2][2];
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>a[i];
if(a[i]==-1)a[i]=0;
A[i+1]=A[i]+a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
if(b[i]==-1)b[i]=0;
B[i+1]=B[i]+b[i];
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1100];
double f[1100][1100], ans = 0;
int main() {
scanf("%d%d", &n, &m);
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
f[i][j] = (a[i] > a[j]), f[j][... | 4 |
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define N 210
#define inf 2147483647
using namespace std;
struct edge{int x, y, l, next;}a[100010];
int n, m, l, p[N], T, x1, y1, x2, y2, lev[N], q[N], ans;
char S[N];
inline void add(int x, int y, int z){
a[++l].x=x; a[l].y=y; a[l].l=z; a[l].next=... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int temp;
vector<int> arr;
bool isprime(int x) {
if (x == 2 || x == 3) return true;
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0) return false;
return true;
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
if (isprime(i) == true) ... | 1 |
//AOJ0118
#include<iostream>
#include<string>
using namespace std;
int H,W;
char table[102][102];
void kesu(int y,int x,char now){
if(table[y][x]!=now)
return ;
table[y][x]='x';
kesu(y+1,x,now);
kesu(y-1,x,now);
kesu(y,x+1,now);
kesu(y,x-1,now);
}
int main(){
while(true){
cin>>H>>W;
if(H==0&&... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
ll N;
ll M;
vector<ll> A;
int main() {
cin >> N >> M;
A.resize(N);
rep(i, N) cin >> A[i];
sort(all(A));
vector<ll> S(N + 1, 0);
rep(i, N) S[i + 1] ... | 0 |
#include <bits/stdc++.h>
void print_array(int *a, int n) {
printf("#");
for (int i = 0; i < n; i++) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
}
using namespace std;
const double EPS = 1e-8;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
int mp[200][200];
int n, m, h;
void optr(int i, i... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int n, A, B, m;
int a[200010], opa[200010], opb[200010];
vector<int> G[200010];
vector<int> rG[200010];
vector<int> vs;
bool used[200010];
int cmp[200010];
void addedge(int u, int v) {
G[u].push_back(v);
rG[v].push_back(u);
}
void init() {
for (int i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 1e15;
void __print(long long int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return a * (b / gcd(a, b));
}
void solve() {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0;... | 5 |
#include <bits/stdc++.h>
int n, k, c[500100];
int main() {
while (scanf("%d%d", &n, &k) > 0) {
for (int i = 0; i < n; i++) {
scanf("%d", &c[i]);
}
long long lo = 0, up = (long long)5e15, val;
while (lo <= up) {
long long mid = (lo + up) >> 1, cnt = 0;
for (int i = 0; i < n and cnt <=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,a,b=0;
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>a;
if(a>k-a)
b+=2*(k-a);
else
b+=2*a;
}
cout<<b<<endl;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
bool check(char s[]) {
int i = 0;
int j = strlen(s) - 1;
while (i <= j) {
if (s[i] != s[j]) return false;
i++;
j--;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
char S[100], s[100];
cin >> S;
int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int mat[N][N];
vector<int> adj[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < m; ++i) {
int u, v;
scanf("%d %d", &u, &v);
--u;
--v;
mat[u][v] = 1;
adj[u].push_back(v);
}
long long ans = 0;
for (... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
cin>>a>>b>>c;
printf("%d %d %d",c,a,b);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
inline T bigmod(T p, T e, T M) {
if (e == 0) retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3030, M = 1e4 + 100;
int n, S, ans, u[N], v[N], w[N], par[N], sz[N], cnt[N];
bool bad;
vector<int> vec[M];
int g_par(int v) { return v == par[v] ? v : par[v] = g_par(par[v]); }
int main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = ... | 5 |
#include <bits/stdc++.h>
int main() {
int m, n, min = 0, max = 0;
scanf("%d", &n);
m = n;
if (n < 7) {
if (n < 3) {
min = 0;
max = n;
} else if (n < 6) {
min = 0;
max = 2;
} else {
min = 1;
max = 2;
}
} else {
if (n % 7 == 0) {
max = (n / 7) * 2;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using cd = complex<double>;
using moveset = array<list<int>, 3>;
struct formula {
int period_length;
vector<int> values;
};
formula deduce_formula(moveset m) {
static constexpr int bulan = 200;
vector<int> vals(2 * bulan, 0);
for (int i = 3; ... | 6 |
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;
ll modpow(ll x,ll n){
ll res=1;
while(n>0){
if(n&1)res=res*x%MOD;
x=x*x%MOD;
n>>=1;
}
return res;
}
struct Combination{
vector<ll> fac,finv,inv;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = numeric_limits<int>::max();
int main() {
int al, ar, bl, br;
cin >> al >> ar >> bl >> br;
cout << ((br <= (al + 1) * 2 && br >= al - 1) ||
(bl <= (ar + 1) * 2 && bl >= ar - 1)
? "YES"
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int pal[25];
vector<int> g[N];
vector<int> comp[N];
int cnt[(1 << 21) + 1337];
bool used[N];
int let[N];
long long ans[N];
int f[30][N];
void init() {
for (int i = 0; i < (N - 1); ++i) used[i] = 0;
for (int i = 0; i < (N - 1); ++i) ans[i] = 0ll;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], k[N];
void init(int n) {
for (int i = 1; i <= n; i++) {
k[i] = 0;
}
}
int main() {
ios_base::sync_with_stdio(0);
int n, d, b;
cin >> n >> d >> b;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n == 2) {
cout <... | 4 |
#include <bits/stdc++.h>
using namespace std;
double ans = 0;
int ne, nf, ns;
double le, lf, ls;
int rf, re, rs;
int de, df;
double interFLen[30][30];
double interELen[30][30];
double inter(double st1, double ed1, double st2, double ed2) {
if (st2 > ed1 || st1 > ed2) return 0;
return min(ed1, ed2) - max(st1, st2);
... | 5 |
#include<bits/stdc++.h>
#define N 305
#define pi pair<int,int>
#define mk make_pair
#define Mod 1000000007
using namespace std;
int n,m,x,y,z,dp[N][N][N];
vector<pi>G[N];
inline bool check(int x,int y,int z){
int pos=max(x,max(y,z));
if (x<y) swap(x,y);if (x<z) swap(x,z);
if (y<z) swap(y,z);
for (int i=0;i<(int)G[p... | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int A;
string S;
set<string> st;
cin>>A;
for(int i = 0;i < A;i++){
cin>>S;
st.insert(S);
}
cout<<st.size();
} | 0 |
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>... | 2 |
#include <bits/stdc++.h>
using namespace std;
int _max(int x, int y) { return x > y ? x : y; }
const long long mod = 1e9 + 7;
int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0'... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int y, w, next;
} path[100005 * 2];
int first[100005], p;
inline void add(int x, int y, int w) {
path[p].y = y;
path[p].w = w;
path[p].next = first[x];
first[x] = p++;
}
int fa[100005][18], dep[100005], bg[100005], ed[100005], idx;
int stn[100005];
v... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long>>> adj;
vector<unordered_set<long long>> tra;
long long n;
long long m;
long long dijkstra() {
long long source = 1;
long long destination = n;
long long var[n + 1];
long long fix[n + 1];
for (long long i = 1; i <= n; i++) {... | 2 |
#include <bits/stdc++.h>
const int N = 1e6 + 5, M = 1e6 + 5;
int n, m, tp, st[N];
struct Edge {
int u, v, w;
bool operator<(const Edge &b) const { return w < b.w; }
} e[M];
struct Tree {
int fa, ch[2], mx, tag, v;
} t[N];
void pushdown(int rt) {
if (!t[rt].tag) return;
t[rt].tag = 0;
std::swap(t[rt].ch[0], ... | 6 |
#include <bits/stdc++.h>
int main() {
int l, r, c;
long long m2, m3;
c = 0;
m2 = 1;
scanf("%d %d", &l, &r);
while (m2 <= r) {
m3 = 1;
while (m2 * m3 <= r) {
if (m2 * m3 >= l) {
c += 1;
}
m3 *= 3;
}
m2 *= 2;
}
printf("%d", c);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
int n = a.size();
int start = 0;
int ans = 0;
for (int i = 0; i < n - 3; i++) {
if (a.substr(i, 4) == "bear") {
ans += (i - start + 1) * (n - i - 3);
start = i + 1;
}
}
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> arr(n);
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> arr[i];
mp[arr[i]]++;
}
if (mp.size() < k) {
cout << -1 << ' ' <<... | 2 |
#include <bits/stdc++.h>
#define f first
#define s second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3fll
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
const int SEED = chrono::steady_clock::now().time_since_epoch().count();
mt19937 rng(SEED);
string p = "haha";
struct item{
str... | 5 |
#include <iostream>
using namespace std;
int main() {
int b[3];
for (int i = 0; i < 3; ++i) cin >> b[i];
if ((b[0] & b[1]) || b[2]) cout << "Open" << endl;
else cout << "Close" <<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, z, i, j, n, m, k, s1, s2, s3, s4, s5, s6, mod, l, r, t, maxx,
minn, sx, so, sum, ans, puk;
double u, v, w, x1, x2, x3, x4, z1, z2, z3, h, huh;
string s;
string q;
string p;
string sq[145];
long long a[1000045];
long long b[1000045];
long long c[1000045];... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, j, i;
string str, str1, str2;
cin >> n;
for (i = 0; i < n; i++) {
cin >> str;
if (str.length() % 2 == 0) {
j = str.length() / 2;
str1 = str.substr(0, j);
str2 = str.substr(j, j);
if (str1 == str2) {
cout <<... | 1 |
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
using namespace std;
const int N=5e5+7;
char s[N];
int a[N],n,now;
int main(){
scanf("%s",s+1);
n=strlen(s+1);
rep(i,1,n)a[i+1]=s[i]-'0';
int c=0;
rep2(i,n+1,1){
int res=a[i]*9 + c;
a[i]=res%10;
c=res... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename U, typename V>
string to_string(pair<U, V>);
string to_string(const string& e_) { return "\"" + e_ + "\""; }
string to_string(char e_) { return "\'" + string(1, e_) + "\'"; }
strin... | 2 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a = 0, b = 0, c = 0, arra[1000], arrb[1000], arrc[1000];
bool h = true, f = true;
char hin;
string hh1, hh2, hh3;
getline(cin, hh1);
getline(cin, hh2);
getline(cin, hh3);
for (int i = 0; hh1[i]; i++) {
if (hh1[i] == 'a' || hh1[i] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
const int LIM = 5e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
vector<int> boo... | 2 |
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
int ans[100];
queue<int> row;
int t = 0, cur = -1;
vector<int> in(17, -1);
while(cur != 99){
// new customer
if(t%5 == 0 && t < 500) row.push(t/5);
// customer leaves
for(int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const long long longinf = 1LL << 60;
const long long mod = 1e9 + 7;
const long double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[300][300], n, k;
int main() {
cin >> n >> k;
a[1][1] = 0;
a[2][1] = 2;
a[2][2] = 1;
a[4][1] = 32;
a[4][2] = 30;
a[4][3] = 80;
a[4][4] = 109;
a[8][1] = 6824;
a[8][2] = 59808;
a[8][3] = 147224;
a[8][4] = 415870;
a[8][5] = 1757896;
a[8][6] = 1... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int zc = 0,oc = 0;
for(int i=0;i<s.size();i++)
{
if(s[i] == '0')zc++;
if(s[i] == '1')oc++;
}
int k = min(zc,oc);
cout<<k*2<<endl;
} | 0 |
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int n,m;
while ( cin >> n >> m, n || m ) {
double f[101][101];
double dp[101][101];
for ( int i = 0; i < n; i++ ) {
for ( int j = 0; j < n; j++ ) {
cin >> f[i][j];
}
}
for ( int i = 0; i <... | 0 |
#include <bits/stdc++.h>
using namespace std;
void init() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
init();
long long int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) cin >> v[i];
vector<long long int> a_min(n), b_max(n);
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long n, u, v, w, ans, cnt;
bool mark[N];
vector<int> adj[N];
bool isLucky(int x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return 0;
x /= 10;
}
return 1;
}
void dfs(int v) {
mark[v] = 1;
cnt++;
for (auto u : adj[v])
i... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int sx,sy,tx,ty;
cin>>sx>>sy>>tx>>ty;
string s="";
for(int i=0;i<ty-sy;i++) s+="U";
for(int i=0;i<tx-sx;i++) s+="R";
for(int i=0;i<ty-sy;i++) s+="D";
for(int i=0;i<=tx-sx;i++) s+="L";
for(int i=0;i<=ty-sy;i++) s+="U";
for(int i=0;i<=tx-sx;i++) s... | 0 |
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
#define MAXN 100000000
int h,w,k,x,y;
long long memory[MAXN], ans[12];
int Sep,tot;
long long z;
int main() {
scanf("%d%d%d",&h,&w,&k);
z=1ll*(h-2)*(w-2);
for(int p=1;p<=k;p++) {
scanf("%d%d",&x,&y);
for(int i=0;i<3;i++)
for(int j=0;j<3;j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, n, b, c = 0, d = 0;
cin >> n;
cout << n << " ";
for (int i = n / 2; i > 0; i--) {
if (n % i == 0) {
cout << i << " ";
n = i;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = pow(2,31)-1;
const int MAX_N = 1<<17;
int n_;
int dat[2*MAX_N-1];
void init(int n) {
n_ = 1;
while (n_<n) {
n_ *= 2;
}
for (int i=0; i<2*n_-1; i++) {
dat[i] = INF;
}
}
void update(int i,int x) {
i += n_-1;
dat[i] = x;
while (i>0) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, e, f, sum1, sum2, max;
cin >> a >> b >> c >> d;
if (a % b == 0)
cout << "0" << endl;
else {
sum1 = min((b - (a % b)) * c, (a % b) * d);
cout << sum1 << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int latin[27] = {0};
char next(int k) {
for (int i = k - 1; i >= 0; --i) {
if (latin[i] == 0) return i + 'a';
}
return 'a';
}
int main() {
int k;
cin >> k;
string s;
cin >> s;
int l = s.length();
if (l < k) {
cout << "IMPOSSIBLE" << endl;
retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
long long x, y;
} arr[100000];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
long long o = 0;
for (long long i = 0; i <= n; i++) {
cin >> arr[i].x >> arr[i].y;
if (i == 0) continue;
o += (arr[i].x - a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], m;
int main() {
cin >> n;
for (int i = (1); i <= (n); i++) {
scanf("%d", &a[i]);
}
cin >> m;
int maxx = 0;
long long maxh = a[1];
for (int i = (1); i <= (m); i++) {
int w, h;
scanf("%d%d", &w, &h);
for (int j = (maxx + 1); j ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (x == 1)
a++;
else
b++;
}
long long ans = 0;
long long x = 1, y = 2;
if (a == 1 || a == 0) ans = 1;
if (a == 2) ans ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, ta;
cin >> a >> ta;
int b, tb, h = 0, m = 0, num;
int totmin;
cin >> b >> tb;
string s;
cin >> s;
for (int i = 0; i < 2; i++) {
h = h * 10 + (s[i] - '0');
}
for (int i = 3; i < 5; i++) {
m = m * 10 + (s[i] - '0');
}
totmin... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Square(ll x) { return x * x; }
ll Divide(ll x, ll d) {
d = min(d, x);
ll group1 = d - x % d;
ll group2 = x % d;
ll res = group1 * Square(x / d) + group2 * Square(x / d + 1);
return res;
}
int main() {
ll i, j, k;
ll n;
cin >> n >> k;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int arr[n];
vector<int> vec;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 1) c++;
if (i && arr[i] == 1) vec.push_back(arr[i - 1]);
}
vec.push_back(arr[n - 1]);
cout << c << endl;
for (int i = 0... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1);
using namespace std;
const int MAX = 100 * 1000 + 10;
vector<int> E[MAX];
int fr[MAX], to[MAX], weight[MAX];
int siz[MAX], max_subtree[MAX], dont[MAX];
int dfs_in[MAX], dfs_out[MAX], dfs_time;
int n, max_l, max_w;
long long ans = 0;
vector<... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long k1, k2, n, m, use[200000], use1[200000];
vector<pair<int, int> > edge[200000];
vector<int> dp[2][2], aa, bb;
int dfs(int i, int j) {
int sum = 0;
if (use[i]) aa.push_back(i);
for (auto v : edge[i]) {
int k = (use[i] + v.second) % 2, p = 0;
if (k != j... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, kol = 0;
cin >> n;
long long a[11] = {0};
long long b[11] = {0};
long long k;
while (cin >> k) {
k >= 0 ? a[k]++ : b[-1 * k]++;
}
kol += (a[0] - 1) * a[0] / 2;
for (int i = 1; i < 11; i++) {
kol += (a[i] * b[i]);
}
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long dp[(1 << 20)];
int msk;
int cnt[21][30];
long long c[21][30];
long long mxc[21][30];
int chMsk[21][30];
long long g[21][21];
int sm[(1 << 20)];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
cin... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
int res = 1;
while (res * (res - 1) / 2 <= n) res++;
res--;
vector<int> Q[res + 10];
int cnt = 1;
for (int i = 1; i <= res; i++) {
for (int j = i + 1; j <= res; j++) {
Q[i].push_back(cnt);
Q[j].push_back(cnt);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
long long int cnt[200005];
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
long long int n, a = 0, b = 0, k1, k2, p, c, x, mx = 0, mn = 0, i, j,
flag = 0, cnt =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d%d", &a, &b);
while (a <= ans) a += b;
ans = a;
}
printf("%d\n", ans);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T x, T y) {
while (T t = x % y) x = y, y = t;
return y;
}
const double eps = 1e-10;
const double PI = acos(-1.);
const int INF = 1000000000;
const int MOD = 1000000007;
const double E = 2.7182818284590452353602874713527;
bool isdig(char x) { ret... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 8, i, c = 0, d = 0;
string s;
while (n--) {
cin >> s;
for (i = 0; i < s.length(); i++) {
if (s[i] == 'Q') c = c + 9;
if (s[i] == 'R') c = c + 5;
if (s[i] == 'B') c = c + 3;
if (s[i] == 'N') c = c + 3;
if (s[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[1005];
bool vis[1005], isgov[1005], hasgov;
int gov[1005], fvc, fec, vcnt, ecnt;
vector<pair<int, int> > govres;
void dfs(int v) {
if (isgov[v]) hasgov = true;
vis[v] = true;
vcnt++, ecnt += G[v].size();
for (int u : G[v])
if (!vis[u]) dfs(u);
}
in... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, int> mm;
int main() {
cin >> n >> m;
int arr[n], ar[m];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < m; i++) {
cin >> ar[i];
mm[ar[i]]++;
}
for (int i = 0; i < n; i++)
if (mm[arr[i]] > 0) cout << arr[i] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn];
int n;
int cnt[maxn];
int main() {
int t;
scanf("%d", &t);
while (t--) {
memset(cnt, 0, sizeof(cnt));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
int l = 1;
int r = 2;
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int T = 20;
const int INF = 1e9;
int n, k;
int a[N];
int step[N];
pair<int, int> g[T][N];
vector<int> add[N];
vector<int> sub[N];
int st[N];
long long sum[N];
int cnt[N];
pair<int, int> getMax(int l, int r) {
int len = r - l;
return max(g[s... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, p[N][N], vis[N];
long double E[N], prob[N], coef[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &p[i][j]);
for (int i = 0; i < n; i++) E[i] = 1e30, prob[i] = 1, coef[i] = 0;
E[n - ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[3005];
bool b[3005];
int main() {
int n, m, p1v = 0;
cin >> n >> m;
vector<pair<long long int, int> > v;
vector<pair<long long int, int> > x;
for (int i = 2; i <= m; i++) x.push_back(make_pair(0, i));
for (int i = 0; i < n; i++) {
long long int p, c;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > Q;
long long res;
int n, A[200010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
for (int i = 1; i <= n; i++) Q.push(A[i]);
res = 0;
if (!(n % 2)) {
long long t... | 4 |
#include <iostream>
#include <vector>
using namespace std;
long long const mod = 1000000007;
long long mod_pow(long long a, long long b){
long long res = 1;
a %= mod;
while(b > 0){
if(b%2 == 1) res = (res * a) % mod;
a = (a * a) % mod;
b /= 2;
}
return res;
}
long long mod_... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, a[200005];
cin >> n;
for (int i = 1; i <= 2 * n; i++) cin >> a[i];
sort(a + 1, a + 2 * n + 1);
cout << a[n + 1] - a[n] << '\n';
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
so... | 2 |
#include <bits/stdc++.h>
const int N = 1e5 + 5;
const int oo = 2e9;
const long long loo = 2e18;
using namespace std;
int main() {
int n;
cin >> n;
long long a[N];
for (int i = 0; i < n; ++i) cin >> a[i];
int m;
cin >> m;
long long h = a[0], x, y;
for (int i = 0; i < m; ++i) {
cin >> x >> y;
cout... | 1 |
#include <bits/stdc++.h>
int main() {
int a, b, i, j;
scanf("%d%d", &a, &b);
for (i = 0; i < a; i++) {
for (j = 0; j < b; j++) {
if (i % 2 == 0)
printf("#");
else if (j < b - 1 && i % 4 == 1)
printf(".");
else if (i % 4 == 3 && j > 0)
printf(".");
else if (i % 4... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long qp(long long a, long long b, long long mod) {
long long t = 1;
while (b) {
if (b & 1) t = t * a % mod;
b >>= 1;
a = a * a % mod;
}
return t;
}
struct DOT {
int x;
int y;
};
inline void read(int &x) {
int k = 0;
char f = 1;
char c = ge... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<string> vec;
int cmp(string a, string b) {
int i = 0, j = 0, cnt = 0;
for (; i < a.size(); i++) {
if (a[i] == b[j])
j++;
else
cnt++;
}
return (b.size() - j) + cnt;
}
void solve() {
string s;
cin >> s;
int mins = 1e6;
for (int i = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007, M = 3e5 + 7;
int powe(int x, int y) {
x = x % mod;
int ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
vector<vector<int> > edg(M);
int arr[M];... | 4 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[10010];
a[0]=1;
a[1]=2;
for(int i=2;i<10010;i++){
a[i]=a[i-1]+i;
}
int n;
while(cin>>n){
cout<<a[n]<<endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long ans1, ans2, ans3;
void solve(long long x, long long y) {
if (y == 0) {
ans3 = x;
ans1 = 1;
ans2 = 0;
return;
}
solve(y, x % y);
long long x2 = ans1;
ans1 = ans2;
ans2 = x2 - (x / y) * ans2;
}
long long ceil(long long x, long long y) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long int n, k;
long double l, v1, v2;
cin >> n >> l >> v1 >> v2 >> k;
long long int g = (n + k - 1) / k;
long double d, lo = 0, hi = 1e9 + 5;
for (int T = 0; T < 72; T++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
string S;
cin >>S;
cout <<S.substr(0, S.size()-8) <<endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
string direc = "RDLU";
const long long MOD2 = (long long)1000000007 * (long long)1000000007;
long long ln... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int ans[51];
int f, l, n, i;
long long p, m;
cin >> n >> m;
if (n == 1) {
cout << 1 << endl;
return 0;
}
p = 1ll << (n - 2);
f = 0;
l = n - 1;
i = 1;
while (p) {
if (m <= p) {
ans[f++] = i;
} else {
ans[l--]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> indegree;
map<string, string> m, ans;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (int i = 1; i <= n; i++) {
string a, b;
cin >> a >> b;
m[a] = b;
indegree[b]++;
}
for (auto it : ... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.