solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
double EPS = 0.00000001;
const long long INF = 1000000007;
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<string> a(n);
pair<int, int> st, en;
for (int i = (0); i < (n); ++i) {
cin >> a[i];
for (int j = (0); j < (m); ++j) {
if (a[i][j] == 'S') {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 60);
struct Node {
int d[3];
Node(int x = 0, int y = 0, int z = 0) {
d[0] = x;
d[1] = y;
d[2] = z;
}
};
vector<Node> points;
Node s[8];
__inline long long sqr(long long x) { return x * x; }
__inline long long calc(const Node &... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n,m,i,j,k,ans=0,b=1,cur,res,mod=1000000007;
cin >> n;
vector<long long> a(n);
for(i=0; i<n; i++){
cin >> a[i];
}
b=1;
for(i=0; i<61; i++){
cur=0;
for(j=0; j<n; j++){
cur+=a[j]%2;
a[j]/=2;
cur%=mod;
}
ans+=(((b*cur)%mod)*... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
vector<double> m(5), w(5);
for (int i = 0; i < 5; ++i) {
cin >> m[i];
}
for (int i = 0; i < 5; ++i) {
cin >> w[i];
}
int score = 0;
double x = 50;
for (int i = 0; i < 5; ++i) {... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int MOD = 1e9 + 7;
int n, m;
long long f[N];
int main() {
f[0] = 1;
for (int i = 1; i < N; ++i) {
f[i] = (i * 1LL * f[i - 1]) % MOD;
}
cin >> n >> m;
if (abs(n - m) > 1) {
puts("0");
return 0;
}
long long ans = (f[n... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long MOD;
void add(long long& x, long long y) {
x += y;
if (x >= MOD) x -= MOD;
}
void take(long long& x, long long y) {
x -= y;
if (x < 0) x += MOD;
}
long long sum(long long a, long long b) {
add(a, b);
return a;
}
long long sub(long long a, long long b) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int A[(int)2e5 + 2];
vector<int> adj[(int)2e5 + 2];
int parent[(int)2e5 + 2];
int val[(int)2e5 + 2] = {0};
void rec(int v) {
int res = 2 * A[v] - 1;
for (int u : adj[v]) {
if (u == parent[v]) continue;
parent[u] = v;
rec(u);
res += max(0, val[u]);
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 10;
vector<int> vc[M], path;
int num[M];
bool vis[M];
void dfs(int u, int pre) {
int len = vc[u].size();
path.push_back(u);
num[u] ^= 1;
vis[u] = true;
for (int i = 0; i < len; i++) {
int v = vc[u][i];
if (!vis[v] && v != pre) {
d... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 2; i++) {
for (int j = i + 2; j < n; j++) {
if (a[i] == a[j]) {
m =... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long long pi, la, aw, d;
cin >> pi >> la >> aw >> d;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<long long>> dp(n + 1, vector<long long>(2));
d... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI = acos(-1);
const int INF = 1e9;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
template <typename T>
T gcd(T a, T b) {
return (b ? __gcd(a, b) : a);
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, x, l, r, m;
int main() {
cin >> n;
int endtime = 0;
while (n--) {
cin >> x;
endtime += x;
}
cin >> m;
while (m--) {
cin >> l >> r;
if (endtime <= l) {
cout << l << endl;
return 0;
} else if (endtime > r) {
continue;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
int sum = 0;
for (int j = 0; j < n; j++) {
cin >> arr[j];
sum = sum + arr[j];
}
int a = 1;
while (1) {
if (n * a >= sum) {
cout << a << e... | 1 |
#include "bits/stdc++.h"
using namespace std;
int main() {
int N;
cin >> N;
vector<double> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}sort(A.begin(), A.end());
for (int i = 1; i < N; i++) {
A[i] = (A[i - 1] + A[i]) / 2;
}
cout << A[N - 1];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, q;
int a[1010];
int main() {
cin >> q;
for (int t = 0; t < q; t++) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> k;
a[k]++;
}
int maxi = 0;
int count = 0;
for (int i = 1; i <= 1000; i++) {
int r = min(i, n - count);... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int p = 31;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long usb, ps2, both;
cin >> usb >> ps2 >> both;
long long m;
cin >> m;
vector<long long> musb, mps2;
for (int i = 0; i < m; i++) {
long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, pri[100005], cnt;
long long ans, num;
bool vis[100005];
map<set<pair<int, int>>, int> mp;
void setup(int h) {
for (int i = 2; i <= h; i++) {
if (!vis[i]) pri[cnt++] = i;
for (int j = 0; j < cnt && i * pri[j] <= h; j++) {
vis[i * pri[j]] = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[10], C[102][102], DP[102][102], i, j, z, c, ans, mx, p;
int main() {
cin >> n;
for (k = 0; k < 10; k++) cin >> a[k];
for (i = 0; i <= n; i++) C[0][i] = 1;
for (j = 1; j <= n; j++)
for (k = 1; k <= j; k++)
C[k][j] = (C[k][j - 1] + C[k - 1]... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 1;
const int INF_INT = 1e9 + 100;
const long long POLTOS = 50;
const long long SOTKA = 100;
const long long P = 1e9 + 7;
const long double eps = 1e-9;
const int base = 257;
const long long M = 500;
const long long MAXN = 1e6 + 1;
const long long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, MOD = 1e9 + 7;
void solve() {
long long k1, k2, k3;
cin >> k1 >> k2 >> k3;
long long n = k1 + k2 + k3;
vector<long long> p(n + 1);
for (long long i = 0; i < k1; i++) {
long long x;
cin >> x;
p[x] = 1;
}
for (long long i... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long X[100005];
long long Y[100005];
long long n;
long long sumx;
long long sumx2;
long long sumy;
long long sumy2;
long long ansx;
long long ansy;
long long ans;
int main() {
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> X[i] >> Y[i];
sumx += X[i];... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,n,ctn,i;string s;
while(cin>>n,n){
cin>>s;
for(a=0;a<n;a++){
char t=s[0];ctn=1;stringstream F;
for(i=1;i<(int)s.length();i++)if(t==s[i])ctn++;else F<<ctn<<t,ctn=1,t=s[i];
F<<ctn<<t,s=F.str();
}
cout<<s<<endl;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[1000000];
int l, i, f[1100000];
bool bo;
void dfs(int a, int b, int c) {
if (bo) return;
if (c > l) {
for (i = 1; i <= l; i++) cout << f[i];
bo = true;
return;
}
if (bo) return;
if (int(s[c - 1]) - 48 < 4 && a) {
for (i = 1; i < c; i++) cout... | 2 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000005];
pair<int, int> dp[1 << 21];
void add(int mask, int ind) {
if (dp[mask].first == ind || dp[mask].second == ind) return;
if (dp[mask].first < ind) {
dp[mask].second = dp[mask].first;
dp[mask].first = ind;
} else if (dp[mask].second < ind)
d... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int l, r, k, i, ans, fl;
cin >> l;
cin >> r;
cin >> k;
ans = 1;
i = 0;
fl = 0;
if (l == 1) {
cout << "1"
<< " ";
fl = 1;
}
while (1) {
ans = ans * k;
if (ans >= l && ans <= r) {
cout << ans << " ";
... | 1 |
#include <bits/stdc++.h>
inline int Rand() { return (rand() << 16) | rand(); }
using namespace std;
const int N = 200005;
const double eps = 1e-9;
map<string, int> col;
string s[N], S[] = {"S", "M", "L", "XL", "XXL", "XXXL"}, ans[N];
map<string, string> w, SS, A;
set<pair<string, pair<int, int> > > q;
int main() {
io... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int p1[maxn], p2[maxn], q[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%d", &p1[i]);
p1[i]--;
p2[p1[i]] = i;
q[i] = n;
}
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int mod = 1e9 + 7;
template <class T>
inline void readInt(T &n) {
n = 0;
T ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)2e18;
long long int MOD = 1000000007;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<string,string> get_subtree(string tree) {
tree.erase(tree.begin());
tree.erase(tree.end()-1);
int point = 0;
for (int i = 0, count = 0; i < tree.size(); i++) {
if (tree[i] == '(') count++;
else if (tree[i] == ')') count--;
else ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[105], p[105];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
p[i] = i;
}
sort(p, p + n, [](int i, int j) { return a[i] < a[j]; });
int sum = 0, cnt = 0;
ostringstream s;
for (int i = 0; i < n; i++)
if ((sum... | 1 |
#include <bits/stdc++.h>
int main() {
int n, k;
scanf("%d %d", &n, &k);
if (n == 1 && k != 2)
printf("0\n");
else if (n == 1 && k == 2)
printf("1\n");
else {
int temp = k - n * 2;
if (temp >= n)
printf("0\n");
else
printf("%d\n", n - temp);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long int check(long long int n) {
if (n % 4 == 0)
return n / 4;
else
return 1 + (n - 6) / 4;
}
void solve() {
long long int n;
cin >> n;
if (n % 2 == 0) {
if (n < 4)
cout << -1 << endl;
else
cout << check(n) << endl;
}
if (n % ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, a[100];
int max = 0;
cin >> n >> l;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] > max) max = a[i];
}
int s = 0, tk;
for (int i = l; i <= max; i++) {
tk = 0;
for (int j = 0; j < n; j++) tk += a[j] / i;
if (s < ... | 3 |
#include <iostream>
using namespace std;
int main()
{
int n, m;
while (cin >> n >> m, n + m)
{
int ary[100] = {};
int p = m;
int i = 0;
while (true)
{
if (p == 0)
{
p = ary[i];
ary[i] = 0;
}
else
{
p--;
ary[i]++;
}
if (ary[i] == m)
{
cout << i << endl;
break... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const int MAXS = 5500;
int N, R;
int F[MAXN], S[MAXN];
long double P[MAXN];
long double dp[MAXN][MAXS];
long double csolve(long double x) {
for (int i = 0; i < MAXS; i++) {
if (i <= R)
dp[N][i] = 0.;
else
dp[N][i] = x;
}
for (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char b[32][32];
int d[2][32][32][256][2];
int t[8], px[8], py[8], v[8], k, o, xs, ys;
bool valid(int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m && b[x][y] == '.';
}
queue<pair<pair<int, int>, pair<int, int> > > q;
int dx[] = {1, -1, 0, 0};
int dy[] = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int q, t;
long long u, v, w, res;
map<long long, long long> mp;
int main() {
cin >> q;
for (int i = 1; i <= q; i++) {
cin >> t >> u >> v;
if (t == 1) {
cin >> w;
if (u < v) swap(u, v);
while (u != v) {
mp[u] += w;
u /= 2;
... | 3 |
#include <bits/stdc++.h>
#define H 128
#define W 17
#define INF 1e4
using namespace std;
int h,w;
string str[H];
/*
short mem[H][W][1<<W];
bool used[H][W][1<<W];
int dfs(int y,int x,int bit,int p,int u){
if( y == h ) return 0;
if(p+(w-x) < str[y].size()) return -INF;
if( x == w ) {
if(p < (int)str[y].siz... | 0 |
#include <bits/stdc++.h>
int get(int k) {
int s, x;
s = 1;
x = 2;
while (k > 0) {
if (k % 2 != 0) s = ((long long)s * x) % 1000000009;
k >>= 1;
x = ((long long)x * x) % 1000000009;
}
return s;
}
int main() {
int n, m, x, y;
scanf("%d %d", &n, &m);
if (m < 31 && n >= (1 << m))
printf("0... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> mp;
int main(void) {
for (int i = 0; i < 100000 + 10; i++) mp[i] = -1;
cin >> n;
int ok = 1;
for (int i = 0; i < n; i++) {
int x, k;
cin >> x >> k;
if (mp[k] < x - 1)
ok = 0;
else
mp[k] = max(mp[k], x);
}
if (ok)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const size_t N = 600 + 5;
const vector<int> BLANK = vector<int>();
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 1e9 + 9;
bool col[N];
int n, pa[N], dep[N];
vector<int> g[N], vert[2];
ll get_hsh(const vector<int> &vc) {
ll hsh1 =... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
template <typename T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), (c > '9' ||... | 2 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n;
const int nMax = 3000 + 9;
int A[nMax];
int main() {
read_file();
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) scanf("%d", &A[i]), A[i] -= i;
priority_queue<pair<int, long long> > PQ;
PQ.push(ma... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, R, r;
cin >> n >> R >> r;
if (n == 1 && R >= r) {
cout << "YES";
return 0;
} else {
if (((R - r) * sin(3.14159265 / n) + .0000001) >= (r))
cout << "YES";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;
}
struct edge
{
int v,next,w;
}vs[300010];
int n,ee,st[300010],size[300010... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 2e5 + 10;
vector<int> v;
bool vis[mn];
vector<int> g[mn];
void dfs(int x) {
vis[x] = 1;
v.push_back(x);
for (int y : g[x]) {
if (!vis[y]) {
dfs(y);
v.push_back(x);
}
}
}
int main() {
int n, m, k, i, j;
scanf("%d%d%d", &n, &m, &... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& op... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int MOD = 1e9 + 7;
int a[5][5], b[5][5];
struct Node {
int x, y;
} vt[N];
int st[N];
int ret(int n1, int n2) {
if (n1 == n2) return 0;
if (n1 == 1 && n2 == 3) return 1;
if (n1 == 3 && n2 == 1) return 2;
if (n1 > n2) return 1;
return... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n;
cin >> n;
string sol = "";
while(n){
n--;
char cur = (n % 26) + 'a';
sol = cur + sol;
n /= 26;
}
cout << sol << '\n';
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int m, n, cnt;
int fa[100050];
int find(int x) {
if (x == fa[x]) return x;
return fa[x] = find(fa[x]);
}
int main() {
int a, b;
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++) fa[i] = i;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a, &b);
int x = f... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, m, n, l, r, k, len;
string s, tem;
int main() {
cin >> s;
n = s.size();
scanf("%I64d", &m);
for (i = 0; i < m; ++i) {
scanf("%I64d%I64d%I64d", &l, &r, &k);
tem = s;
l--;
r--;
len = r - l + 1;
k %= len;
for (j = l; j < l + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
int n[100];
int A[100][100];
for(int j=0; j<t; j++){
cin>>n[j];
for(int i=0; i<n[j]; i++){
cin>>A[j][i];
}
}
int min[100];
int Count[100];
for(int j=0; j<t; j++){
min... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, flag;
cin >> n >> m;
int l[m], ans[n], check[n];
memset(ans, 0, sizeof(ans));
memset(check, 0, sizeof(check));
for (int i = 0; i < m; i++) cin >> l[i];
for (int i = 0; i < m - 1; i++) {
if (l[i + 1] > l[i]) {
flag = 0;
if... | 2 |
#include <bits/stdc++.h>
#define repeat(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
int main()
{
int N, M;
cin >> N >> M;
vector<ll> A(max(N, M), 0);
priority_queue<p> Q;
ll result = 0;
repeat(i, N) {
ll a;
cin >> a;
Q.push( make_pair(a, 1) );... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[2010],mn[2010];
int main(){
int i,j,n,x;
long long s,ans=1e18;
scanf("%d%d",&n,&x);
for(i=0;i<n;++i)scanf("%d",a+i),mn[i]=a[i];
for(i=0;i<n;++i){
for(j=s=0;j<n;++j)s+=mn[j];
ans=min(ans,s+1ll*x*i);
for(j=0;j<n;++j)mn[j]=min(mn[j],a[(j-i-1+n)%n]);
}
printf... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
long long x, y;
} a[8101], b[8101], p;
long long ans;
int i, j, k, n, ty;
long long cp(pt o, pt a, pt b) {
return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
bool cmp(pt a, pt b) {
if (a.y > ty && b.y < ty) return 1;
if (a.y < ty && b.y > ty... | 5 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int t,x,y,n,q,k,l,r;
ll ans,s[2010],dp[2010][2010],m;
map<ll,int> p;
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%lld",&s[i]);
}
sort(s+1,s+n+1);
for (int i=2;i<=n;i++)
for (int j=1;j+i-1<=n;j++)
dp[j... | 3 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) {
string s = "'";
s += c;
return s + "'";
}
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A,... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int c = 1;
long long uni = 0;
for (int u = 0; u < m; u++) {
int i;
cin >> i;
if (i >= c) {
uni += i - c;
} else {
uni += (n - c) + (i);
}
c = i;
}
cout << uni << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int r, c, n, k, a, b;
int ans;
int mat[11][11];
int main() {
scanf("%d%d%d%d", &r, &c, &n, &k);
memset(mat, 0, sizeof(mat));
for (int i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
mat[a][b] = 1;
}
for (int y = 1; y <= r; y++) {
for (int x = 1; x <= c; x+... | 1 |
#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<stdio.h>
#include<string>
using namespace std;
string str[50];
char temp[21];
int in[9];
int v[50];
int w[50];
int main(){
int a;
while(scanf("%d",&a),a){
for(int i=0;i<a;i++){
scanf("%s",temp);
str[i]=temp;
for(int j=0;j<9;j++)scanf("%d",in+j);
v[i]=(in[6]*in[7]*in[8]-in[0]);
w[i]=(in[1]+in... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long pow(long long di, long long c) {
long long ans = 1;
while (c--) ans *= di;
return ans;
}
long long dig[3000000];
int main() {
for (int i = 1; i < 16; i++) {
dig[i] = i * 9 * (long long)pow(10, i - 1) + dig[i - 1];
}
long long k;
cin >> k;
for (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f7f7f7f;
const int MAXN = 305;
const double eps = 1e-10;
int maze[MAXN][MAXN];
int dis[2][MAXN * MAXN];
int n, m, p;
struct node {
int x, y, len, id;
node(int x = 0, int y = 0, int len = 0, int id = 0)
: x(x), y(y), len(len), id(id) {}
};
vector... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N, Q;
int A[200002], AIB[200002];
void update(int pos, int val) {
for (; pos <= 200000; pos += pos & -pos) AIB[pos] += val;
}
int query(int pos) {
int sum = 0;
for (; pos >= 1; pos -= pos & -pos) sum += AIB[pos];
return sum;
}
int main() {
cin.sync_with_stdio(... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
struct edge {
int to, next;
} e[maxn << 1];
int head[maxn], size[maxn], n, cnt;
double f[maxn];
void link(int u, int v) {
e[++cnt] = (edge){v, head[u]};
head[u] = cnt;
}
void dfs(int x) {
size[x] = 1;
for (int i = head[x]; i; i = e[i].next... | 4 |
#include<bits/stdc++.h>
using namespace std;
double f[305][305][305];int t[3],a,n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a),t[a-1]++;
for(int i=0;i<=n;i++)
for(int j=0;j<=n-i;j++)
for(int k=0;k<=n-i-j;k++){
if(!i&&!j&&!k) continue;
double sm=i+j+k,p=n/sm;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, n, dp[40009][52];
long long tavan(long long x, long long y) {
long long p;
if (y == 0) return 1;
if (y % 2 == 0) {
p = tavan(x, y / 2);
return (p * p);
}
return (tavan(x, y - 1) * x);
}
void d(int x, int y) {
if (x == 1 && y > b) return;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 50;
int n, m, q, a[maxn][maxn], valid[maxn][maxn][maxn][maxn],
dp[maxn][maxn][maxn][maxn], ans[maxn][maxn][maxn][maxn];
inline void init() {
cin >> n >> m >> q;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
char hlp;
cin ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int x, y, m;
int main() {
cin >> x >> y >> m;
if (x >= m || y >= m) {
cout << 0 << endl;
return 0;
}
if (y <= 0 && x <= 0) {
cout << -1 << endl;
return 0;
}
long long int i = 0;
if (x < 0 || y < 0) {
if (x < 0) {
i += (-x) /... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a1 = 0, b1 = 0, a, b, flag = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
if (!flag) {
if (a - a1 < 0 || b - b1 < 0)
flag = 1;
else {
if ((b - b... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long x) {
if (x % 4 == 0) return x;
if (x % 4 == 1) return 1;
if (x % 4 == 2) return x + 1;
return 0;
}
int n;
long long res = 0;
int main() {
cin >> n;
long long x, y;
while (n--) {
cin >> x >> y;
long long t = f(x - 1) ^ f(x + y - 1)... | 3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=0;
while(cin>>n,n){
int people[n];
for(int i=0;i<n;i++)cin>>people[i];
sort(people,people+n);
long long int ans=0,now=0;
for(int i=0;i<n;i++){
ans+=now;
now+=people[i];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> arr(1e5 + 6, 0);
vector<long long int> dp(1e5 + 5, 100000000000000000);
long long int L = 0;
long long int R = 0;
long long int c = 0;
vector<long long int> data(1e5 + 5, 0);
void erase(long long int x) { c -= (--data[arr[x]]); }
void add(long long int... | 6 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MX=5e5+9;
const ll mod=1e9+7;
ll n,m;
ll fac[MX],ifac[MX];
ll pow(ll a,ll b){
ll ans=1;
while( b ){
if( b&1 )
ans=(ans*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return ans;
}
ll prem(ll x,ll y){return f... | 0 |
#include <bits/stdc++.h>
using namespace std;
int ara[105];
int main() {
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
int twos = 0, ones = 0, zeros = 0;
for (int i = 0; i < n; i++) {
cin >> ara[i];
ara[i] %= 3;
if (ara[i] == 2)
twos++;
else if (ara[i] == 1)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
long long x = 0;
bool f = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = 1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
}
long long n, m... | 5 |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const long long MOD=1e9+7;
long long dp[110][100010];
int main()
{
int n,k;
cin>>n>>k;
vector<int>a;
for(int i=1;i<=n;)
{
a.emplace_back(n/i);
i=n/(n/i)+1;
}
int m=a.size();
sort(a.begin(),a.end());
for(int i=0;i<=m;i++)
dp[1... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int a, b;
cin >> a >> b;
cout << max<int>(0, a-2*b);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a[3010];
vector<pair<int, int> > ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
int pb = i;
for (int j = i; j < n; j++) {
if (a[pb] > a[... | 1 |
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n... | 0 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[200005];
map<int, int> a, b;
int fact[200005];
int main() {
int n;
long long ans = 1, MOD, num, k, val;
n = ({
int t;
scanf("%d", &t);
t;
});
for (int i = 0; i < 2 * n; i++)
arr[i] = make_pair(({
int t;
... | 2 |
#include<iostream>
using namespace std;
int main()
{
int x;
cin>>x;
if(x%2==0)
cout<<x;
else
cout<<x*2;
return 0;
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200003;
int n, q;
struct Edge {
int u, v, w;
} edge[MaxN * 2];
vector<pair<int, int> > e[MaxN];
int fa[MaxN], dep[MaxN], sz[MaxN], id[MaxN], idx;
long long dist[MaxN], weight[MaxN];
void dfs(int x) {
id[x] = ++idx;
for (pair<int, int>& i : e[x]) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int get() {
int n;
char c;
while ((c = getchar()) || 1)
if (c >= '0' && c <= '9') break;
n = c - '0';
while ((c = getchar()) || 1) {
if (c >= '0' && c <= '9')
n = n * 10 + c - '0';
else
return (n);
}
}
int deg[1000001];
int ints[10... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int u, v, w;
} edg[1000000];
int group[100001] = {}, n, m, aaa, bbb, a, b, e, gc;
bool cmp(Edge a, Edge b) {
if (a.w < b.w)
return true;
else if (a.w > b.w)
return false;
else
return false;
}
int fnd(int a) {
if (a == group[a])
return... | 5 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin>>n;
int a;cin>>a;int a1=a;
int max=0;int ran=0;
for(int i=1;i<n;++i)
{
cin>>a;
if(a<=a1){a1=a;ran++;if(ran>max){max=ran;}}
else{ran=0;a1=a;}
}
cout<<max;
} | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <class T>
class _Fenwick {
private:
std::vector<T> sum;
int _size;
public:
_Fenwick() { _size = 0; }
void reset(int n) {
... | 4 |
#include<bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
double a[21][3],ans=0,p;int n,m,c[21];
using namespace std;
double cal(){p=0;
r(i,0,m)r(j,i+1,m)
p+=pow(a[c[i]][0]-a[c[j]][0],2)+pow(a[c[i]][1]-a[c[j]][1],2)+pow(a[c[i]][2]-a[c[j]][2],2);
ans=max(ans,p);
}
void dfs(int x,int d){
if(d==m){cal();return... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-6;
const int maxn = 1e3 + 5;
const int maxm = 1e6 + 5;
const int dx[... | 2 |
#include <bits/stdc++.h>
using namespace std;
unsigned int n, m;
unsigned int dp[21][1 << 20];
char t[20][100009];
int main() {
scanf("%u %u", &n, &m);
for (unsigned int i = 0; i < n; i++) scanf(" %s", t[i]);
for (unsigned int i = 0; i < m; i++) {
unsigned int mask = 0;
for (unsigned int j = 0; j < n; j++... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long k;
int n;
cin >> n >> k;
vector<int> a(n);
for (int &x : a) cin >> x;
map<long long, int> kuroni;
for (int &x : a) ++kuroni[x];
while (k > 0) {
auto p = kuroni.begin();
auto ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 100;
vector<int> E[maxn];
vector<int> EE[maxn];
int dis[maxn];
int n, m;
int d[maxn];
bool in[maxn];
void spfa(int root) {
queue<int> Q;
for (int i = 1; i <= n; i++) {
dis[i] = inf;
}
in[root] = 1;
dis[root] =... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool solve(long long n, long long k, long long d1, long long d2) {
long long arr[4][3];
arr[0][0] = d1;
arr[0][1] = 0;
arr[0][2] = d2;
arr[1][0] = d1 + d2;
arr[1][1] = d2;
arr[1][2] = 0;
arr[2][0] = 0;
arr[2][1] = d1;
arr[2][2] = d2 + d1;
if (d1 > d2)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MN = 1e5 + 100;
long long a[MN];
long long need[MN];
queue<long long> q;
long long n, m, w;
bool check(long long x) {
for (long long i = 0; i < n; i++) {
need[i] = max(0ll, x - a[i]);
}
long long ans = 0, sum = 0;
for (long long i = 0; i < n; i++... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
for (i = 1; i < n; i++) {
if (i % 2 == 1) {
cout << "I hate that ";
} else {
cout << "I love that ";
}
}
if (n % 2 == 1) {
cout << "I hate it" << endl;
} else if (n % 2 == 0) {
cout << "I love it" ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int x, y;
while(cin >> x >> y){
if(x==0 && y==0)
break;
if(x>y)
swap(x, y);
cout << x << " " << y << endl;
}
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)
struct Vec{
double x,y;
Vec(double xx, double yy) : x(xx),y(yy) {}
Vec operator+() const {return Vec(x,y);}
Vec operator-() const {return Vec(-x,-y);}... | 0 |
#include <iostream>
using namespace std;
long long a[90];
int main()
{
int n;
cin>>n;
a[0]=2;
a[1]=1;
for(int i=2;i<=86;i++) a[i]=a[i-1]+a[i-2];
cout<<a[n]<<endl;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.