prompt string | response string |
|---|---|
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int gi() {
char cc = getchar();
int cn = 0, flus = 1;
while (cc < '0' || cc > '9') {
if (cc == '-') flus = -flus;
cc = getchar();
}
while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
return cn * flus;
}
const int P = 1e9 + 7;
const i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long mo = 1000000007;
int a[505], cnt[505], P[505], n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] != -1) cnt[a[i]]++;
}
P[0] = 0;
for (int i = 1; i <= n; i++) P[i] = (P[i - 1] * 2 + 1) % mo;
int a... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int a[555], d[555], pw[555];
int main() {
int n;
cin >> n;
int mod = 1e9 + 7;
for (int i = pw[0] = 1; i <= n; i++) {
cin >> a[i];
pw[i] = pw[i - 1] * 2 % mod;
if (~a[i]) d[a[i]]++;
}
int ans = pw[n - 1] - 1;
for (int i = 1; i <= n; i++)
if (a[i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
int t(int a, int ans = 1) {
while (a--) {
ans <<= 1;
if (ans >= mod) ans -= mod;
}
return ans;
}
int main() {
int n;
cin >> n;
vector<int> g(n + 1, 0);
for (int i = 1; i <= n; i++) {
int d;
cin >> d;
if (~d) g[d]++;
}
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
const int Mod = 1e9 + 7;
const int maxn = 510;
int pw[maxn ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | n=int(input())
a=input().split()
print((2**(n-1)-1-sum([2**a.count(x)-1 for x in set(a)-set(['-1'])]))%(10**9+7)) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int bit[510];
int u, cnt[510], n;
int main() {
scanf("%d", &n);
bit[0] = 1;
for (int i = 1; i <= n; i++) bit[i] = (bit[i - 1] << 1) % 1000000007;
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
if (u != -1) cnt[u]++;
}
int ans = bit[n - 1] - 1;
for (in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int N = 510;
const int moder = int(1e9) + 7;
int a[N];
int e[N];
int cnt[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
int fa = a[i] == -1 ? i : a[i];
++cnt[fa];
}
e[1] = 114514;
e[2] = 2 * e[1] - 1;
for (int i = 2; i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int SUB(int x, int y) { return (x -= y) < 0 ? x + M : x; }
int ADD(int x, int y) { return (x += y) >= M ? x - M : x; }
int MUL(int x, int y) { return (long long)x * y % M; }
const int N = 510;
int a[N], n;
int p2[N];
int main() {
scanf("%d", &n);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int bit[1001], cnt[1001];
int main() {
int u, n;
cin >> n;
bit[0] = 1;
for (int i = 1; i <= n; i++) {
bit[i] = (bit[i - 1] << 1) % 1000000007;
}
for (int i = 1; i <= n; i++) {
cin >> u;
if (u != -1) {
cnt[u]++;
}
}
int ans = bit[n - 1] ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(vector<T> &vec) {
for (int i = 0; i < (int)(vec).size(); i++)
cout << vec[i] << (i == (int)(vec).size() - 1 ? '\n' : ' ');
}
long long exp(long long a, long long x) {
if (x == 0) return 1LL;
if (x == 1) return a % 1000000007;
long long... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, const U &b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, const U &b) {
if (a < b) a = b;
}
template <class T>
inline void gn(T &first) {
char c, sg = 0;
while (c = getchar(), ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 501;
int n, p[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x != -1) p[x]++;
}
int sum = 0;
for (int i = 1; i <= n; i++) {
int x = 1;
for (int j = 0; j < p[i]; j++) x *= 2, x... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int mod = 1000000007;
int n, c[510], pw[510];
int main() {
scanf("%d", &n);
for (int i = n, a; i--;) scanf("%d", &a), a > -1 ? c[a]++ : 1;
for (int i = *pw = 1; i < n; i++) pw[i] = pw[i - 1] * 2 % mod;
int s = pw[n - 1] - 1;
for (int i = n; i; i--) s = (s + mod - pw[c[i]] + 1) %... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int N = 505, P = 1000000007;
int n, cnt[N];
int fpow(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % P)
if (b & 1) res = 1ll * res * a % P;
return res;
}
int main() {
scanf("%d", &n);
for (int i = (1); i <= (n); ++i) {
int x;
scanf("%d", &x);
if... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 510;
const int mod = 1e9 + 7;
long long n, p[MAXN], a[MAXN], S, T, x;
long long read() {
long long x = 0, sgn = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') sgn = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int addmod(int x) { return x >= mod ? x - mod : x; }
inline int submod(int x) { return x < 0 ? x + mod : x; }
int n, a[100005], vis[100005], pw[100005], pn = 1e5;
int main() {
pw[0] = 1;
for (int i = 1; i <= pn; i++) pw[i] = 2 * pw[i - 1]... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long g = 31623;
long long n, sum;
long long cnt[510], poww[32000][2];
long long read() {
long long r = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c <= '9' && c >= '0') r = (r << 1) + ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
long long f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f *= -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - 48;
ch = getchar();
}
x *= f;
}
long long n, mod = 1... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long read() {
long long 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';
ch = getchar();
}
return s * f;
}... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using LLI = long long;
long long NWD(long long a, long long b) { return (b == 0) ? a : NWD(b, a % b); }
long long NWW(long long a, long long b) { return a / NWD(a, b) * b; }
const int N = 504, MOD = 1e9 + 7;
int n, wynik, a[N], liczek[N], pot[N];
inline int normalize(int x)... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int maxn = 500;
constexpr unsigned long long mod = 1e9 + 7;
int cnt[maxn + 10];
unsigned long long quickPow2(unsigned long long e) {
unsigned long long ret = 1, acc = 2;
for (; e; e >>= 1) {
if (e & 0x01) ret = (ret * acc) % mod;
acc = (acc * acc) % mod;
}
return ret;
}
un... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? EOF : *ib++;
}
inline int read() {
char ch = gc();
int res = 0;
bool f = 1;
while (!isdigit(c... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int read() {
int f = 1, x = 0;
char c = (int)getchar();
while (c < '0' || '9' < c) {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f * x;
}
const int MAXN = 1000000;
cons... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long N = 505, M = 1000000007;
inline int read() {
int f = 1, x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
return f * x;
}
int n, cnt[N];
int qiwang(int x, ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
struct mint {
int val = 0;
mint() {}
mint(int a) : val(a) {
while (val < 0) {
val += M;
}
while (val >= M) {
val -= M;
}
}
mint(long long a) : val(a % M) {
if (val < 0) {
val += M;
}
}
mint op... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int Imx = 2147483647;
const long long Lbig = 2e18;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | n=int(input())
r=list(map(int,input().split()))
f=[0]*501
for t in r:
if t>=0:f[t]+=1
print((2**(n-1)-1-sum(2**k-1 for k in f)) % 1000000007) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
inline int read() {
int r = 0, f = 0;
char c;
while (!isdigit(c = getchar())) f |= (c == '-');
while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar();
return f ? -r : r;
}
int n, f[555];
long long ans, p[555];
int main() {
n = read();
p[0] = 1;
for (int i = 1; i <=... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long QuickPow(long long x, long long p) {
long long base = x, ans = 1;
while (p) {
if (p & 1) ans *= base, ans %= MOD;
p >>= 1;
base *= base;
base %= MOD;
}
return ans;
}
long long n, deg[505];
int main() {
sc... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200005, P = 1000000007;
ll n, x, ans, sz[N];
ll qpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) ret = ret * a % P;
a = a * a % P;
b >>= 1;
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using ll = long long;
static auto constexpr maxn = 600;
static auto constexpr mo = 1000000007ll;
int a[maxn];
int count[maxn];
ll pow2[maxn];
int n;
ll mul(ll lhs, ll rhs) { return (lhs * rhs) % mo; }
ll add(ll lhs, ll rhs) { return (lhs + rhs) % mo; }
void init() {
pow2[0] = 1;
for (auto i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int supd(int a) { return a >= 0 ? a : a + 1000000007; }
int n, pw[505], siz[505];
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * 2 % 1000000007;
for (int i = 1; i <= n; ++i) {
int fa;
scanf("%d", &fa);
if (fa !=... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | n,a=int(input()),input().split();print((pow(2,n-1)-1-sum(pow(2,a.count(x))-1for x in{*a}-{'-1'}))%(10**9+7)) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int kN = 500 + 5;
const int MOD = (int)1e9 + 7;
int n;
int c[kN];
int pw2[kN];
int main() {
pw2[0] = 1;
for (int i = 1; i < kN; ++i) pw2[i] = pw2[i - 1] * 1LL * 2 % MOD;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
if (x == -1)
++c[i];
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Z_p {
using Type = typename decay<decltype(T::value)>::type;
static vector<Type> mod_inv;
constexpr Z_p() : value() {}
template <typename U>
Z_p(const U &x) {
value = normalize(x);
}
template <typename U>
static Type normaliz... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 11, mod = 1e9 + 7;
int n, m, x;
int c[N], ans, t[N];
inline void inc(int &x, int y) {
x += y;
if (x >= mod) x -= mod;
}
int main() {
scanf("%d", &n);
for (register int i = 1; i <= n; ++i) {
scanf("%d", &x);
if (x != -1) ++c[x];
}
t[0]... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
return (!b) ? a : gcd(b, a % b);... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 5e2 + 2;
const int mod = 1e9 + 7;
void add(int &x, int y) {
x += y;
if (x >= mod) {
x -= mod;
}
}
void sub(int &x, int y) {
x -= y;
if (x < 0) {
x += mod;
}
}
int mul(int x, int y) { return (1ll * x * y) % mod; }
int pw2[N], ar[N], cnt[N];
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, P = 1e9 + 7;
const double Pi = acos(-1);
inline int read() {
int x = 0, f = 1, ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar()... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline void cmin(T &a, T b) {
((a > b) && (a = b));
}
template <class T>
inline void cmax(T &a, T b) {
((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
T s = 0;
int f = 0;
while (!isdigit(IO = getchar())) f |= IO == '-';
do s... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << " = " << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << " = " << h << ", ";
_dbg(sdbg + 1, a...);
}
cons... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int mod = 1e9 + 7;
template <typename _T>
void read(_T &x) {
x = 0;
char s = getchar();
int f = 1;
while (s > '9' || s < '0') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + (s - '0'), s = getchar();
}
x *= f;
}... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int power(int a, int b, int ans = 1) {
for (; b; b >>= 1, a = 1ll * a * a % mod)
if (b & 1) ans = 1ll * ans * a % mod;
return ans;
}
int a[555], b[555];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int mod = 1000000007;
int bin[N], c[N], p, n, ans;
int main() {
scanf("%d", &n);
bin[0] = 1;
for (int i = (1); i <= (n); i++) {
scanf("%d", &p);
if (~p) c[p]++;
bin[i] = 2 * bin[i - 1] % mod;
}
ans = bin[n - 1] - 1;
for (int ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | /**
* author: derrick20
* created: 1/25/21 12:29 AM
*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class CompanyAcquisitions {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
long long pw[502], n, sz[502], ans, M = 1e9 + 7;
int main() {
scanf("%lld", &n);
for (int i = pw[0] = 1, x; i <= n; ++i)
pw[i] = 2 * pw[i - 1] % M, scanf("%d", &x), x > 0 && ++sz[x];
for (int i = 1; i <= n; ++i) ans += pw[sz[i]] - 1;
printf("%lld", (pw[n - 1] - 1 - ans % M + M) % M)... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long int pi = 1000000007;
long long int p2[502];
int main() {
p2[0] = 1;
for (int i = 1; i < 502; i++) {
p2[i] = (p2[i - 1] * 2) % pi;
}
int n;
cin >> n;
vector<int> a;
a.assign(n + 2, 0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline long long Read() {
long long ans = 0, x = 1;
char ch = getchar();
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') x = -1;
for (; '0' <= ch && ch <= '9'; ch = getchar())
ans = (ans << 3) + (ans << 1) + (ch ^ '0');
return ans * x;
}
const ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int inf32 = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3f;
const int M = 1e9 + 7;
struct mint {
int x;
mint(int x = 0) : x(x) {}
friend mint operator+(const mint a, const mint &b) {
int x = a.x + b.x;
return mint(x >= M ? x - M : x);
}
frien... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
inline long long read() {
register long long x = 0, f = 1;
register char c = getchar();
for (; !isdigit(c); c = getchar(... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void read(_T &f) {
f = 0;
_T fu = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fu = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
f = (f << 3) + (f << 1) + (c & 15);
c = getchar();
}
f ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | n = int(input())
a = [int(i) for i in input().split()]
b = [0] * (n + 1)
sum = 2 ** (n - 1) - 1
for i in a:
if(i > 0):
b[i] = b[i] + 1
for i in b:
sum = sum - 2 ** i + 1
print(sum % 1000000007)
|
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
struct {
inline operator int() {
int x;
return scanf("%d", &x), x;
}
template <class T>
inline void operator()(T &x) {
x = *this;
}
} read;
const int maxn = 505, mod = 1000000007;
int a[maxn];
int tot[maxn];
long long f[maxn];
int main() {
int n = read;
for (int i = 1;... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
inline int power(int a, int b) {
int out = 1;
while (b) {
if (b & 1) out = (long long)out * a % mod;
a = (long long)a * a % mod;
b >>= 1;
}
return out;
}
int n, cnt[510];
int main() {
scanf("%d", &n);
for (int i = 1, a; i ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long solve(vector<int> freq) {
long long ans = 0;
for (int i = 0; i < freq.size(); i++) {
if (freq[i] > 0) {
long long num = 1;
for (int j = 0; j < freq[i] - 1; j++) {
num = (num + num) % MOD;
}
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long M = 1e6 + 5, JYY = 1e9 + 7;
long long read() {
long long x = 0, y = 1;
char ch = getchar();
while (ch < '0' || ch > '9') y = (ch == '-') ? -1 : 1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * y;
}... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int mod = 1e9 + 7;
int cnt[N];
long long Pow(long long x, int y) {
long long res = 1;
while (y) {
if (y & 1) res *= x;
res %= mod;
y >>= 1;
x *= x;
x %= mod;
}
return res;
}
int main() {
int n;
scanf("%d", &n);
for ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int M = 550;
const long long Mod = 1e9 + 7;
long long bit[M], cnt[M], ans;
int n, x;
int main() {
scanf("%d", &n);
bit[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (x != -1) ++cnt[x];
bit[i] = bit[i - 1] * 2ll % Mod;
}
ans = bit[n -... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | m,n,a = 1000000007,int(input()),input().split()
print((pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != '-1')) % m) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
inline long long pow(long long a, long long b, long long p) {
long long rtn = 1;
while (b) {
if (b & 1) rtn = rtn * a % p;
a = a * a % p;
b >>= 1;
}
return rtn;
}
void makedata() {
freopen("input.tx... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.util.Scanner;
import java.util.*;
import java.util.logging.XMLFormatter;
import static java.lang.Math.*;
public class Main {
static long mod = (long) (1e9 + 7);
static long modPow(int x) {
int res = 1;
for (int i = 0; i < x; i++) {... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
inline int fmo(int x) { return x + ((x >> 31) & 1000000007); }
inline int fp(int x, int k) {
int res = 1;
for (; k; k >>= 1, x = 1ll * x * x % 1000000007)
if (k & 1) res = 1ll * res * x % 1000000007;
return res;
}
int n;
int cnt[505];
int ans;
int main() {
scanf("%d", &n);
for (in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int MOD = int(1E9) + 7;
const int MAXN = 100000;
int pw[MAXN + 5], cnt[MAXN + 5];
void init() {
pw[0] = 1;
for (int i = 1; i <= MAXN; i++) pw[i] = 2LL * pw[i - 1] % MOD;
}
int tot[MAXN + 5];
int main() {
init();
int n, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sca... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &a) {
T 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 << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
a = x *... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const long long mod = 1000000007;
long long n, _2[1010], cnt[1010], ans;
signed main() {
scanf("%lld", &n);
for (long long i = 1, x; i <= n; i++) {
scanf("%lld", &x);
if (x > 0) cnt[x]++;
}
_2[0] = 1;
for (long long i = 1; i <= n; i++) _2[i] = _2[i - 1] * 2 % mod;
for (long ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, cnt[510] = {0}, ans;
int power(int a, int b) {
int ret = 1;
while (b) {
if (b & 1) ret = 1ll * ret * a % mod;
b >>= 1;
a = 1ll * a * a % mod;
}
return ret;
}
int main() {
scanf("%d", &n);
an... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int X = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
X = (X << 3) + (X << 1) + ch - '0', ch = getchar();
return X * w;
}
int n, ans, bt[507], son[507... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long n, a[2000005], num[2000005], ans;
long long ksm(long long x, long long y) {
long long ans = 1, t = x;
while (y) {
if (y & 1) ans = ans * t % 1000000007;
t = t * t % 1000000007;
y >>= 1;
}
return ans;
}
int main() {
scanf("%lld", &n);
for (l... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
map<int, int> M;
int modPow(long long int b, int e) {
long long int r = 1;
while (e > 0) {
if (e & 1) r *= b, r %= 1000000007;
e >>= 1;
b *= b, b %= 1000000007;
}
return r;
}
int main() {
int i;
int n, a, c = 0;
vector<int> v;
scanf("%d", &n);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int MAXN = 500, MOD = 1e9 + 7;
int n, d[MAXN + 5];
inline int qkpow(int a, int b, const int p = MOD) {
int ret = 1;
for (; b; a = 1ll * a * a % p, b >>= 1) ret = 1ll * ret * (b & 1 ? a : 1) % p;
return ret;
}
int main() {
scanf("%d", &n);
int ans = (MOD + qkpow(2, n - 1) - 1) % ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7;
inline int read() {
int neg = 1, num = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') neg = -1;
for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - '0';
return neg * num;
}
int n, cnt[200010];
i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int mod = 1e9 + 7;
int n, cnt[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
if (x != -1) cnt[x]++;
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
int x = 1;
for (int j = 1; j <=... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
void ckmax(T1 &a, T2 b) {
if (a < b) a = b;
}
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int MOD = int(1E9) + 7;
const int MAXN = 100000;
int pw[MAXN + 5], cnt[MAXN + 5];
void init() {
pw[0] = 1;
for (int i = 1; i <= MAXN; i++) pw[i] = 2LL * pw[i - 1] % MOD;
}
int main() {
init();
int n, x;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
i... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const long long N = 510, Mod = 1e9 + 7;
inline long long read() {
long long s = 0, w = 1;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int fsp(int x, int p = mod - 2) {
int res = 1;
while (p) {
if (p & 1) res = 1ll * res * x % mod;
x = 1ll * x * x % mod, p >>= 1;
}
return res;
}
int n, cnt[555];
int main() {
cin >> n;
for (int i = 1, x; i <= n; ++i) {
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | m,n,a=1000000007,int(input()),input().split()
print((pow(2,n-1)-1-sum(pow(2,a.count(x))-1 for x in set(a) if x!='-1'))%m) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int p = 1e9 + 7, N = 1e6 + 7;
long long n, cnt[N], opt[N];
int main() {
int x;
scanf("%d", &n), opt[0] = 1;
for (int i = 1; i <= n; i++) opt[i] = opt[i - 1] * 2 % p;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (x > 0) ++cnt[x];
}
int ans = 0... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long s[110000], a[110000];
int main() {
int n;
scanf("%d", &n);
a[0] = 1;
for (int i = 1; i <= 500; i++) a[i] = a[i - 1] * 2 % 1000000007;
memset(s, 0, sizeof(s));
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (x != -1) s[x]++;
}
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int MAXN = 505;
template <typename _T>
void read(_T &x) {
x = 0;
char s = getchar();
int f = 1;
while (s > '9' || s < '0') {
if (s == '-') f = -1;
s = getchar();
}
while (s >= '0' && s <= '9') {
x = (x << 3) + (x << 1) + (s - '0'), s = getc... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long binpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
long long mod... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | mod = 1000000007
n = int(raw_input())
arr = map(int, raw_input().split())
followers = [0 for __ in xrange(n+1)]
for x in arr:
if x != -1:
followers[x] += 1
final_pot = (pow(2, n-1, mod) - 1) % mod
current_pot = sum((pow(2, x, mod) - 1) % mod for x in followers)
print (final_pot - current_pot) % mod |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, F = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') F = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * F;
}
int add(int a, int b) {
r... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
static const long long PRIME = 1e9 + 7;
static const long long N = 510;
long long potential[N];
inline long long add(long long a, long long b) { return (a + b) % PRIME; }
int main(int argc, char const* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1000000007;
const int UNDEF = -1;
const int INF = 1 << 30;
template <typename T>
inline bool chkmax(T &aa, T bb) {
return aa < ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | n,a=int(input()),input().split()
print((pow(2,n-1)-1-sum(pow(2,a.count(x))-1for x in{*a}-{'-1'}))%(10**9+7)) |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int M = 550;
const long long Mod = 1e9 + 7;
long long bit[M], cnt[M], ans;
int n, x;
int main() {
scanf("%d", &n);
bit[0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (x != -1) ++cnt[x];
bit[i] = bit[i - 1] * 2ll % Mod;
}
ans = bit[n -... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 505, M = 1e9 + 7;
int sub(int a, int b) {
a -= b;
if (a < 0) return a + M;
return a;
}
int qpow(int a, int p) {
int rt = 1, pa = a;
for (; p; p >>= 1, pa = pa * 1ll * pa % M)
if (p & 1) rt = rt * 1ll * pa % M;
return rt;
}
int n;
inline void in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, N = 505;
inline int add(const int& a, const int& b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
inline int sub(const int& a, const int& b) {
return a - b < 0 ? a - b + MOD : a - b;
}
int n;
int key[N], cnt[N];
int main() {
scanf("%d", &n);
... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
const int mod = 1000000007;
int n, c[510], pw[510];
int main() {
scanf("%d", &n);
for (int i = n, a; i--;) scanf("%d", &a), a > -1 ? c[a]++ : 1;
for (int i = *pw = 1; i < n; i++) pw[i] = pw[i - 1] * 2 % mod;
int s = pw[n - 1] - 1;
for (int i = n; i; i--) s = (s + mod - pw[c[i]] + 1) %... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
const int mod = 1e9 + 7;
int a[MAXN], b[MAXN];
long long qpow(long long a, long long b, long long mod) {
long long res = 1;
while (b) {
if (b & 1) {
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
int main... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
long long n, a[2000005], num[2000005], ans;
long long ksm(long long x, long long y) {
long long ans = 1, t = x;
while (y) {
if (y & 1) ans = ans * t % 1000000007;
t = t * t % 1000000007;
y >>= 1;
}
return ans;
}
int main() {
scanf("%lld", &n);
for (l... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int supd(int a) { return a >= 0 ? a : a + 1000000007; }
int n, pw[505], siz[505];
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; ++i) pw[i] = pw[i - 1] * 2 % 1000000007;
for (int i = 1; i <= n; ++i) {
int fa;
scanf("%d", &fa);
if (fa !=... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(register T& t) {
register T f = 1;
register char ch = getchar();
t = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
while (ch >= '0' && ch <= '9') t = t * 10 + ch - '0', ch = getchar();
t ... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline int M(int x) { return (x >= 1000000007) ? (x - 1000000007) : x; }
inline int M1(int x) { return (x < 0) ? (x + 1000000007) : x; }
inline int ksm(int p, int k) {
int res = 1;
while (k) {
if (k & 1) res = 1ll * res * p % 1000000007;
k >>= 1;
p = 1ll * p... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
struct {
template <typename T>
inline operator T() {
T x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) (c == '-') && (f = -1), c = getchar();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f * x;
}
} gi;
const in... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
inline int32_t modpow(uint_fast64_t x, uint64_t k, int32_t MOD) {
assert(x < (uint_fast64_t)MOD);
uint_fast64_t y = 1;
for (; k; k >>= 1) {
if (k & 1) (y *= x) %= MOD;
(x *= x) %= MOD;
}
assert(y < (uint_fast64_t)MOD);
return y;
}
inline int32_t modinv_n... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
const int N = 510, P = 1e9 + 7;
int n, x, pw[N], cnt[N];
int main() {
scanf("%d", &n);
pw[0] = 1;
for (int i = 1; i <= n; i++) pw[i] = pw[i - 1] * 2 % P;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (~x) cnt[x]++;
}
int ans = pw[n - 1] - 1;
for (... |
Problem: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup.
The following step... | #include <bits/stdc++.h>
using namespace std;
int n, cnt[1000010], ans;
int quick(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % 1000000007)
if (b & 1) res = 1ll * res * a % 1000000007;
return res;
}
int main() {
cin >> n;
ans = quick(2, n - 1) - 1;
for (int i = 1; i <= n; i++) {
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.