solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
unsigned long long n;
string s;
unsigned long long cal(unsigned long long l) {
if (l == -1) return 0;
unsigned long long k = 1, z = 0;
for (unsigned long long i = l; i >= 0; i--) {
if ((z + (s[i] - '0') * k) < n) {
z = z + (s[i] - '0') * k;
k *= 10;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline long long getInt() {
long long ret;
char ch;
bool flg = false;
while ((ch = getchar()) < '0' || ch > '9') flg |= (ch == '-');
ret = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') ret = ret * 10 + (ch - '0');
return flg ? -ret : ret;
}
const int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long long sum = 0;
cin >> n;
for (int i = 0; i < n; i++) {
char x;
cin >> x;
if (x == 'B') {
sum += pow(2, i);
}
}
cout << sum;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, i, l, r, a[300300];
pair<int, long long> p;
map<int, pair<int, long long> > m;
long long sum, cur, res;
vector<int> v;
int main() {
res = -1000000000;
res *= 1000000000;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (m.count(a[i])... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <int MOD_>
struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) ... | 5 |
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std ;
int main()
{
int a , b , c , d ;
cin>>a>>b>>c>>d;
int x = c-a , y = d-b ;
cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 40;
int n;
char s[MAXN + 1];
int slen;
long long dp[MAXN][MAXN][MAXN + 1];
long long sum[MAXN + 1];
bool can[MAXN][MAXN];
long long solve() {
for (int i = (0); i < (n); ++i) can[i][i] = true;
... | 6 |
#include <iostream>
using namespace std;
int main(){
int A,B,K;
cin>>A>>B>>K;
for(int i=0;i<K;i++){
if(i%2==0){
B+=A/2;
A/=2;
}else{
A+=B/2;
B/=2;
}
}
cout<<A<<" "<<B;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
namespace flow {
const int M = 10000, N = 200;
int second[M], nxt[M], gap[N], fst[N], c[N], pre[N], q[N], dis[N];
int f[M];
int S, T, tot, Tn;
void init(int s, int t, int tn) {
tot = 1;
assert(tn < N);
for (int(i) = (0); (i) < (tn); (i)++) fst[i] = 0;
S = s;
T = t... | 6 |
#include<iostream>
#include<cstdio>
#define M 100000
using namespace std;
int main(){
int n;
int m;
int l;
int pos = 0;
int ans = 0;
int x[100000];
scanf("%d %d",&n,&m);
x[0] = 0;
for (int i = 1; i < n; i++){
scanf("%d", &x[i]);
x[i] += x[i - 1];
}
while (m... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s,s[0]!='#'){
int sl=s.length();
int ans=0;
vector<int>memo(30,-1);
queue<string>s1,s2;
for(int i=0;i<(1<<sl);++i){
string a=s;
for(int j=0;j<sl;++j){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
int n, k;
cin >> n >> k;
set<int> st;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
st.insert(x);
}
int Min = *st.begin();
if (Min - 1 <= k) return ... | 5 |
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
int e;
while(cin>>e and e>0){
int ans=10000000;
for(int i=0;i*i*i<=e;i++){
for(int j=0;j*j<=e-i*i*i;j++){
int m=i+j+e-(i*i*i+j*j);
if(ans>m) ans=m;
}
}
cout<<ans<<en... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T a, T b) {
T x;
if (b == 0)
x = 1;
else
x = a;
for (size_t i = 1; i < b; i++) x *= a;
return x;
}
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
long long int n, m, a, b, c, ab, ba, ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int a[n + 1];
set<long long int> s;
for (long long int i = (long long int)1; i <= (long long int)n; i++) {
cin >> a[i];
s.insert(a[i]);
}
vector<long long int> temp;
temp.push_back(-1);
map<long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n;
cin >> n;
unordered_map<long long, long long> mp;
unordered_map<long long, vector<long long>> graph;
unordered_map<long long, long long> indegree;
vector<long long> v(n);
for (long long i = 0; i < n; i++) {
long long x;
ci... | 4 |
#include<bits/stdc++.h>
using namespace std;
int n,k;
int main()
{
scanf("%d%d",&k,&n);
for(int i=n-k+1;i<=n+k-1;i++) printf("%d ",i);
} | 0 |
#include <iostream>
using namespace std;
int main() {
int n,t[100],s=0,p,x;
cin >> n;
for(int i =0;i<n;i++){
cin >> t[i];
s += t[i];
}
cin >> n;
for(int i=0;i<n;i++){
cin >> p >> x;
cout << s - t[p-1] + x << endl;
}
} | 0 |
#include <bits/stdc++.h>
const long long INF = (1LL << 60) - 1;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
x = x % 1000000007;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res;
}
long long BINARY_SE... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <typename T>
T gcd(T a, T b) {
T m;
while (b != T(0)) {
m = a % b;
a = b;
b = m;
}
return a;
}
template <typename T>
T lcm(T a, T b) {
return a == 0 && b == 0 ? 0 : (a / gcd(a,... | 3 |
#include <bits/stdc++.h>
using namespace std;
int M = 100;
int color[50][50];
int n, r1, c1, r2, c2;
int otv = 0;
void bfs(int p, int q, int c) {
color[p][q] = c;
for (int dp = -1; dp < 2; dp++)
for (int dq = -1; dq < 2; ++dq)
if (dp * dp + dq * dq == 1 && p + dp >= 0 && p + dp < n && q + dq >= 0 &&
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int oddness = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
for (int j = 0; j < m; j++) {
cout << "#";
}
} else {
++oddness;
for (int j = 0; j < m; j++) {
if (oddness % 2 == 1... | 1 |
#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 eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n = 0, ct = 0, x = 0, ct2 = 0;
cin >> n;
long long int arr[n + 1];
for (int a = 0; a < n; a++) cin >> arr[a];
bool ok = false;
arr[n] = -1000000000000000000;
for (int a = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
vector<vector<int> > Maze;
int n;
int Getp(int v, int p) {
int ans = 0;
while (v && v % p == 0) {
v /= p;
ans++;
}
return ans;
}
int dp[N][N];
void update(int i, int j, int c) {
if (dp[i][j] == -1)
dp[i][j] = c;
else
dp[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10 + 10, MAXM = 1 << 6;
int n;
int r[MAXN][MAXN], bits[MAXM];
bool checka(int v) {
int a[3], tn = 0;
for (int i = 0; i < (5); i++) {
if ((v >> i) & 1) {
a[tn++] = i;
}
}
int ans = 0;
for (int i = 0; i < (3); i++) {
for (int j = (... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
if (x < y) x = y;
}
using LL = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int INF = 0x3f3f3f3f;
const int MOD = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s, p;
int main() {
cin >> n;
if (n <= 9) return cout << n << endl, 0;
for (int i = 10; i <= n; ++i) {
int x = i;
char ch;
s = "";
while (x > 0) {
ch = (x % 10) + '0';
s = ch + s;
x /= 10;
}
p += s;
}
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 60;
void imin(long long& l, long long r) { l = min(l, r); }
const long long N = 1024;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
vector<long long> a(n + 1);
for (long lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = std::tuple<int, int>;
const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1},
dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};
int N, C;
int A[500100];
int cnt[500100], cnt2[500100], nxt[500100];
int dp[500100];
int main() {
std::cin.tie(nullptr);
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct str {
int a, b;
bool operator<(const str& A) const { return a - b > A.a - A.b; }
};
int main() {
int n, m;
long long sum = 0;
str arr[100002];
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d %d", &arr[i].a, &arr[i].b);
sum += arr... | 3 |
#include <bits/stdc++.h>
using namespace std;
int N;
vector<string> A[26];
bool cmp(const string& lhs, const string& rhs) { return lhs + rhs < rhs + lhs; }
bool wrap(const string& lhs, const string& rhs) {
bool r = cmp(lhs, rhs);
return r;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
fo... | 3 |
#include <bits/stdc++.h>
int a[6];
int main() {
for (int i = 0; i < 6; i++) {
scanf("%d", &a[i]);
}
int h = a[1] + a[2];
int ans = 0, w = a[0], nw;
for (int i = 0; i < h; i++) {
if ((i < a[1]) && (i < a[5]))
nw = w + 1;
else if ((i < a[1]) ^ (i < a[5]))
nw = w;
else
nw = w - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
int sum(0);
int miin2(-100000), miin(100000);
for (int i(0); i < n; i++) {
cin >> x;
if (x > 0) {
sum += x;
if (x % 2 != 0) {
miin = min(miin, x);
}
}
if (x < 0 && x % 2 != 0) {
miin2... | 2 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std;
int main()
{
int N, M;
scanf("%d%d", &N, &M);
vector<int> A(N+1), B(M+1);
const int MAX_N = N*M;
constexpr long long int MOD = 1000000007;
for(int i = 0; i < N; ++i) scanf("%d", &A[i]);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int c[MAXN], id[MAXN];
bool flag[MAXN][2];
int a[4][MAXN], an[4];
long long ans, cur, s0cnt;
multiset<int> s0, s1;
bool comp(int a, int b) { return c[a] < c[b]; }
int main() {
int n, m, k, minx;
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
long long m = 1e9;
for (auto e :... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll solve(const vector<int> &a, int l, int r, int waterline) {
int next_waterline = *min_element(begin(a) + l, begin(a) + r);
ll res2 = (ll)next_waterline - waterline;
if (res2 > (ll)r - l) {
return r - l;
}
int start = -1;
int island_mi... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int bef[55][55][4][2];
string mp[55];
long long int n, k;
long long int dx[] = {0, 1, 0, -1};
long long int dy[] = {1, 0, -1, 0};
int run(long long int turn, long long int x, long long int y, long long int dp,
long long int cp) {
if (turn == k) {
cou... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tpl = tuple<int, int, int>;
using pcc = pair<char, char>;
const int inf = 9999999;
const ll mod = 1e9 + 7;
int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int kr[] = {-1, 1, -2, -2, -1, 1, 2, 2};
int kc[] = {-2, -2... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long n, k, m, p, TC;
long long h;
long long base = 1;
long long solve(int level, long long curr_val, long long b, long long e,
bool from_left) {
if (level == h) {
return curr_val - 1;
}
if (n <= (b + e) / 2) {
long long new_curr;... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, l, r, mn = 1e10;
cin >> n >> m;
for (long long i = 0; i < m; ++i) {
cin >> l >> r;
mn = min(mn,... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int n;
string s;
int d[MAXN];
bool vis[... | 2 |
#include "stdio.h"
int day;
int num;
int temp[201];
int wear[200];
int dp[201][200] = {};
int min[201] = {};
int max[201] = {};
int ans=0;
int abs(int a) {
if (a > 0)return a;
return -a;
}
int Max(int a, int b) {
if (a > b)return a;
return b;
}
int main() {
scanf("%d %d", &day, &num);
for (int i = 0; i < day;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int f[N], n, pos[N], num[N], in[N];
vector<pair<int, int>> edge[N];
int visited[N];
queue<pair<int, int>> q;
bool dfs(int u, int k, int fa) {
num[u] = 1;
for (auto e : edge[u]) {
int v = e.first, Edge = e.second;
if (!visited[Edge] && v != f... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-10;
const long long mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
c... | 5 |
/*
* @Author: your name
* @Date: 2021-03-05 15:16:23
* @LastEditTime: 2021-03-06 22:33:30
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \code_formal\cf\CF_700_3.cpp
*/
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#incl... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_wit... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int c... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
struct P {
long long x, y;
P(long long x = 0, long long y = 0) : x(x), y(y) {}
} p[N], S[N];
long long Dis(P a, P b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
P operator+(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P opera... | 5 |
#include <bits/stdc++.h>
const int kN = 500000 + 5;
int n, k;
std::vector<std::pair<int, int>> edges[kN];
using LL = long long;
LL f[kN][2];
void dfs(int u, int fa, int wa) {
std::vector<LL> vec;
LL s = 0;
for (auto t : edges[u]) {
int v = t.first;
int w = t.second;
if (v != fa) {
dfs(v, u, w);
... | 3 |
#include <iostream>
using namespace std;
int main()
{
int s, w;
cin >> s >> w;
cout << (w>=s?"unsafe":"safe") << endl;
} | 0 |
#include<bits/stdc++.h>
using namespace std;
int n,a,sum;
int main()
{
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>a;sum+=a-1;
}
cout<<sum<<endl;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 510000;
const int M = 5100000;
const int mod = 1e9 + 7;
const int inf = (int)1e9;
const double eps = 1e-9;
const long long INF = 1e11;
int n, k, m;
int id1[N], intree[N];
int dep[N], f[N];
int sz[N], son[N], dfn[N], fat[N], arr[N], cnt;
vector<int> g[N];
pair<... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 5;
string s[MAXN];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
string ans = "";
for (int j = 0; j < (int)s[0].length(); j++) {
bool b = false, b2 = false;
char ch = '?';
for (int i = 0; i < n; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int n;
int q,x;
vector<int>v;
int main(){
cin>>n;
while(n--){
cin>>q;
if(q==2)v.pop_back();
if(q==0){
cin>>x;
v.push_back(x);
}
if(q==1){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005, md = 998244353;
int n, ans, sa, sb, sc;
struct node {
int a, b;
} nm[N];
int fac[N];
bool cmp1(node a, node b) {
if (a.a == b.a) return a.b < b.b;
return a.a < b.a;
}
bool cmp2(node a, node b) { return a.b < b.b; }
template <class I>
inline void ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n,i,nr,x,aux;
int main()
{
cin>>n;
i=5;
if(n%2==0)
while(i<=n)
nr=nr+n/(i*2) , i=i*5;
cout<<nr;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int par[200005], n;
long long ans;
map<long long, long long> comp, use;
map<int, vector<pair<int, int> > > mm;
vector<pair<long long, pair<int, int> > > Q;
void intialize() {
for (int i = 1; i <= n; i++) par[i] = i;
}
int parent(int x) {
if (par[x] != x) {
par[x] = ... | 6 |
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
long m,h,w,s[3];
cin>>h>>w;
m=h*w;
for(int i=1;i<h;i++)
{
s[0]=i*w;
if(w%2&&(h-i)%2)
{
s[1]=min(w,h-i)*(max(w,h-i)-1)/2;
s[2]=min(w,h-i)*(max(w,h-i)+1)/2;
}
else
{
s[1]=s[2]=w*(h-i)/2;
}
sort(s,s+3);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct team {
int h;
int a;
};
int main() {
int n;
int c = 0;
cin >> n;
team t[100];
for (int i = 0; i < n; i++) {
cin >> t[i].h;
cin >> t[i].a;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (t[i].a == t[j].h) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int r;
scanf("%d", &r);
return r;
}
pair<int, int> A[200050];
int cnt, n, m, rt, a, b, c, d, k;
void GP(int &a, int &b, pair<int, int> P) { a = P.first, b = P.second; }
struct Node {
int l, r, siz, key, F, G;
} tr[200050];
int up(int t) {
tr[t].s... | 4 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set>
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[101][101];
long long b[101];
int main() {
int m, n;
cin >> m >> n;
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) cin >> a[i][j];
for (int i = 0; i < m; i++) {
long long minn = 100000000000000;
for (int j = 0; j < n; j++) {
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long powm(long long base, long long exp, long long mod = 1000000007) {
long long ans = 1;
while (exp) {
if (exp & 1) ans = (ans * base) % mod;
exp >>= 1, base = (base * base) % mod;
}
return ans;
}
struct Point {
long long x, y;
} pts[2005];
map<pair<... | 4 |
#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 eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 * 1000 + 10;
const double eps = 1e-9;
int n, k, h;
pair<pair<int, int>, int> a[maxN];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k >> h;
for (int i = 1; i <= n; i++) cin >> a[i].first.first;
for (int i = 1; i <= n; i++) cin >> a[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j;
double k, l, t, r, w, e;
double x, y;
cin >> x >> y;
cin >> n;
double mi = 10000000000000;
while (n--) {
cin >> k >> l >> e;
t = abs(k - x) * abs(k - x);
r = abs(y - l) * abs(y - l);
w = sqrt(t + r);
mi = ... | 1 |
#include<bits/stdc++.h>
const int N=100005;
using namespace std;
int n,to[N*2],hd[N*2],lk[N],cnt,
re[N],f[N],sz[N],de[N];
bool vis[N];
inline void add(int u,int v){
to[++cnt]=v,hd[cnt]=lk[u],lk[u]=cnt;
}int u,v;
void dfs(int x){
sz[x]=1;
for(int s,i=lk[x];i;i=hd[i])
if(f[x]^(s=to[i]))
f[s]=x,de[s]=de[x]+1,dfs(s),
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int s[20000] = {0}, h[10] = {0}, n, m, k, i, j, x, y;
short int a[20000][10];
cin >> n >> m >> k;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) cin >> a[i][j];
for (i = 0; i < k; i++) {
scanf("%ld%ld", &x, &y);
h[y - 1]++;
s[x -... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
long long n, b[2 * MAXN], a[2 * MAXN], m;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
long long s = 0;
for (int i = 0; i < n; ++i) {
cin >> b[i];
s += b[i];
}
for (int i = 0; i < n; ++i) b[i... | 5 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long ll;
bool debug = false;
const double eps = 1e-10;
clock_t START, END;
str... | 0 |
#include <bits/stdc++.h>
using namespace std;
int A[105];
int N, M;
vector<int> v;
int main() {
scanf("%d%d", &N, &M);
int o = 0;
for(int i = 1; i <= M; i++) {
scanf("%d", &A[i]);
if(A[i] & 1) o++;
}
if(o > 2) { puts("Impossible"); return 0; }
if(M == 1) {
if(N == 1) printf("1\n1\n1\n");
else printf("%... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
if (n == 1) {
cout << 0 << "\n";
co... | 4 |
#include<cstdio>
int main() {
int n,a,b;
scanf("%d\n%d\n%d",&n,&a,&b);
printf("%d\n",(n-a+1)*(n-b+1));
} | 0 |
#include <bits/stdc++.h>
#define endl '\n'
#define all(a) (a).begin(), (a).end()
#define len(a) (int) (a).size()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define int long long
using namespace std;
void solve();
mt19937 rnd(2009);
signed main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freop... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, ans;
int x[1100000], pw[1100000];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
sort(x + 1, x + n + 1);
pw[0] = 1;
for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % 1000000007;
for (int i = 1; i < n; i++)
ans = (ans... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[200][200], deg[200];
stack<pair<long long int, long long int> > stk;
int main() {
long long int n, m;
cin >> n >> m;
for (long long int i = 0; i < m; i++) {
long long int u, v;
cin >> u >> v;
deg[u]++;
deg[v]++;
arr[u][v] = 1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
struct info {
bool legal, l_2;
int lis[3], cnt;
void merge(const info &b) {
static int cur[6];
int tot = cnt;
for (int i = 0; i < cnt; i++) cur[i] = lis[i];
for (int i = 0; i < b.cnt; i++) cur[tot++] = b.lis[i];
sort(cur, c... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
int gcd(int x, int y) {
while (y) {
int t = x % y;
x = y;
y = t;
}
return x;
}
int n;
long long a[1000100], b[1000100];
long long sa[1000100], sb[1000100];
int id[1000100];
map<long long, int> mp;
int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int v1, v2, v3, vm;
int vm1, vm2, vm3;
int main() {
cin >> v1 >> v2 >> v3 >> vm;
vm1 = 2 * v1;
vm2 = 2 * v2;
vm3 = max(v3, vm);
if (vm3 > 2 * min(v3, vm)) {
cout << "-1";
return 0;
}
if (vm1 <= 2 * vm || vm2 <= 2 * vm) {
cout << "-1";
return 0;... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool possible[27], flag, visit[27];
char str[121212];
int n, ans, res = 26;
int main() {
cin >> n;
getchar();
for (int i = 0; i < 26; i++) possible[i] = 1;
for (int j = 1; j <= n; j++) {
char ch = getchar();
getchar();
scanf("%s", str);
getchar();
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, z;
cin >> n >> k;
int ct = 1;
z = n;
for (int i = 1; i <= n; i++) {
if (k == n - 1) {
cout << z << ' ';
z--;
} else {
k++;
cout << i << ' ';
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
bool arr[1000009] = {0};
void sieve() {
arr[0] = 1;
arr[1] = 1;
for (int i = 2; i < 1000009; i++) {
if (arr[i] == 0) {
for (int j = i * 2; j < 1000009; j += i) {
arr[j] = 1;
}
}
}
}
int main() {
int n, m, index = 1;
cin >> n >> m;
f... | 1 |
#include<bits/stdc++.h>
using namespace std;
int N, M, ap[100009];
long long h[100009];
vector < pair < int, int > > v[100009];
void dfs (int nod)
{
ap[nod] = 1;
for (auto it : v[nod])
if (ap[it.first] == 0)
h[it.first] = h[nod] + it.second, dfs (it.first);
}
int main ()
{
//freopen ("in... | 0 |
#include<cstdio>
using namespace std;
int main(void)
{
int a,b,c,d,h1,h2,k1,k2;
scanf("%d %d %d %d %d %d %d %d",&h1,&h2,&k1,&k2,&a,&b,&c,&d);
if((a*h1)+(b*h2)+(h1/10*c)+(h2/20*d)<(a*k1)+(b*k2)+(k1/10*c)+(k2/20*d)){
printf("kenjiro\n");
}
if((a*h1)+(b*h2)+(h1/10*c)+(h2/20*d)>(a*k1)+(b*k2)+(k1/10*c)+(k2/20*d)){
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 3) + (s << 1) + (ch ^ 48);
ch = getchar(... | 6 |
#include <iostream>
using namespace std;
int main(){
int n,p,i,stc;
int hstc[50];
while(1){
cin >> n >> p;
if (n==0&&p==0) break;
stc = p;
for (i=0;i<n;i++) hstc[i]=0;
i=0;
while(1){
if (stc >0){
stc--;
hstc[i]++;
if (hstc[i]==p) break;
}else{
stc=hstc[i];
hstc[i]=0;
... | 0 |
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
cout << (n*180-360) << "\n";
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long c, m, f;
cin >> c >> m >> f;
long long ans = min(c, m);
c -= ans;
m -= ans;
long long ct = c + m + f;
if (ct >= ans)
cout << ans << endl;
else {
long long v = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
return out << "(" << a.first << "," << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
out << "";
for (auto it = a.begin(); it != a.end()... | 2 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct P {
int H, W;
P(int w, int h) : H(h), W(w) {}
P(){}
bool operator < (const P &a) const
{
return H*W < a.W*a.H;
}
};
int main()
{
int N, W, H;
while (cin>>N>>W>>H, N||W||H) {
vector<P> piece;
piece.empl... | 0 |
#include <bits/stdc++.h>
using namespace std;
int qpow(long long a, long long b, long long m) {
long long c = 1;
while (b) {
if (b & 1) c = c * a % m;
b >>= 1;
a = a * a % m;
}
return c;
}
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int a;
for (int i = (0); i < (n); ++i) {
... | 1 |
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
using namespace std;
const int N = 2e5;
char a[N*3+3];
int n,m;
int main()
{
scanf("%d%d",&n,&m);
scanf("%s",a+1); for(int i=1; i<=n; i++) a[i] -= 65;
int tag = 0,hd = 1,tl = n;
for(int i=1; i<=n+n; i++)
{
if((a[hd]^tag)==0) {a[hd]^=1;}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char gameGrid[10], mark;
int b, c;
bool isOver(char gameGrid[]) {
for (int k = 1; k <= 9; k++) {
if (gameGrid[k] == '.') {
return false;
}
}
return true;
}
bool checkValid(char gameGrid[]) {
b = 0;
c = 0;
for (int a = 1; a <= 9; a++) {
if (game... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int w = 0, flg = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
flg = -1;
}
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
w = w * 10 + ch - '0', ch = getchar();
}
return w * flg;
}
int head[110],... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int n, m, x, y, w, cnt, col[maxn], dis[maxn], vis[maxn], d[maxn], head[maxn];
struct node {
int nxt, to, val;
} e[maxn << 1];
void add(int x, int y, int w) {
e[++cnt].to = y;
e[cnt].nxt = head[x];
head[x] = cnt;
e[cnt].val = w;
}
queue<i... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int y, d, m;
} a, b;
int _m[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int _ml[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isleap(int y) {
if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) return true;
return false;
}
int main()... | 2 |
#include <iostream>
using namespace std;
int main(){
int N;
int n=1;
cin >> N;
while(n<=N){
n *= 2;
}
cout << n/2;
return 0;
} | 0 |
#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;
}
typedef long long ll;
ll mod=1000000007;
int main()
{
int n=read(),p=0;
ll ans=1;
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.