problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02728
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cstring> #include <iostream> // #include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int MOD = 1e9 + 7; const int N = 4e5 + 10; long long dp[N] = {0}, ans[N] = {0}; long long fact_ret[N] = {0}; int tree_size[N] = {0}; int visit[N] = {0}; struct edge { int v, next; } edges[N]; int e_cnt = 0; int head[N]; void add(int u, int v) { edges[e_cnt].v = v; edges[e_cnt].next = head[u]; head[u] = e_cnt++; } void cal_fact() { fact_ret[0] = 1; for (int i = 1; i < N; ++i) fact_ret[i] = fact_ret[i - 1] * i % M; } int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) { int64_t d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a) { int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x % MOD) % MOD; } int cal_size(int root) { visit[root] = 1; if (tree_size[root] != 0) return tree_size[root]; tree_size[root] = 1; for (int e = head[root]; e != -1; e = edges[e].next) { if (visit[edges[e].v]) continue; tree_size[root] += cal_size(edges[e].v); } return tree_size[root]; } int cal_dp(int root) { // cout << "dp " << root << endl; visit[root] = 1; if (dp[root] != 0) return dp[root]; dp[root] = fact_ret[tree_size[root] - 1]; if (tree_size[root] == 1) return dp[root]; for (int e = head[root]; e != -1; e = edges[e].next) { int v = edges[e].v; // cout << "v " << v << endl; if (visit[v]) continue; dp[root] = dp[root] / fact_ret[tree_size[v]] % M; dp[root] = (dp[root] * cal_dp(v)) % M; } return dp[root]; } void root_transfer(int root) { visit[root] = 1; for (int e = head[root]; e != -1; e = edges[e].next) { int u = root, v = edges[e].v; if (visit[v]) continue; long long new_size_v = tree_size[u]; long long new_size_u = tree_size[u] - tree_size[v]; assert(("No zero", dp[v] != 0)); long long new_dp_u = dp[u] * fact_ret[tree_size[v]] % M * fact_ret[new_size_u - 1] % M * inv_mod(dp[v]) % M * inv_mod(fact_ret[tree_size[u] - 1]) % M; long long new_dp_v = dp[v] * new_dp_u % M * fact_ret[new_size_v - 1] % M * inv_mod(fact_ret[new_size_u]) % M * inv_mod(fact_ret[tree_size[v] - 1]) % M; long long old_size_v = tree_size[v], old_size_u = tree_size[u], old_dp_u = dp[u], old_dp_v = dp[v]; ans[v] = new_dp_v; dp[u] = new_dp_u; dp[v] = new_dp_v; tree_size[u] = new_size_u; tree_size[v] = new_size_v; // cout << root << ' ' << v << ' ' << new_dp_u << ' ' << new_dp_v << endl; root_transfer(v); dp[u] = old_dp_u; dp[v] = old_dp_v; tree_size[u] = old_size_u; tree_size[v] = old_size_u; } } int main() { memset(head, -1, sizeof(head)); memset(dp, 0, sizeof(dp)); memset(fact_ret, -1, sizeof(fact_ret)); int n; cin >> n; for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; add(a, b); add(b, a); } cal_fact(); memset(visit, 0, sizeof(visit)); memset(tree_size, 0, sizeof(tree_size)); cal_size(1); memset(dp, 0, sizeof(dp)); memset(visit, 0, sizeof(visit)); cal_dp(1); ans[1] = dp[1]; memset(visit, 0, sizeof(visit)); root_transfer(1); for (int i = 1; i <= n; ++i) cout << ans[i] << endl; return 0; }
#include <algorithm> #include <cassert> #include <cstring> #include <iostream> // #include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7; const int MOD = 1e9 + 7; const int N = 4e5 + 10; long long dp[N] = {0}, ans[N] = {0}; long long fact_ret[N] = {0}; int tree_size[N] = {0}; int visit[N] = {0}; struct edge { int v, next; } edges[N]; int e_cnt = 0; int head[N]; void add(int u, int v) { edges[e_cnt].v = v; edges[e_cnt].next = head[u]; head[u] = e_cnt++; } void cal_fact() { fact_ret[0] = 1; for (int i = 1; i < N; ++i) fact_ret[i] = fact_ret[i - 1] * i % M; } int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) { int64_t d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int64_t inv_mod(int64_t a) { int64_t x, y; extgcd(a, MOD, x, y); return (MOD + x % MOD) % MOD; } int cal_size(int root) { visit[root] = 1; if (tree_size[root] != 0) return tree_size[root]; tree_size[root] = 1; for (int e = head[root]; e != -1; e = edges[e].next) { if (visit[edges[e].v]) continue; tree_size[root] += cal_size(edges[e].v); } return tree_size[root]; } int cal_dp(int root) { // cout << "dp " << root << endl; visit[root] = 1; if (dp[root] != 0) return dp[root]; dp[root] = fact_ret[tree_size[root] - 1]; if (tree_size[root] == 1) return dp[root]; for (int e = head[root]; e != -1; e = edges[e].next) { int v = edges[e].v; // cout << "v " << v << endl; if (visit[v]) continue; dp[root] = dp[root] * inv_mod(fact_ret[tree_size[v]]) % M; dp[root] = (dp[root] * cal_dp(v)) % M; } return dp[root]; } void root_transfer(int root) { visit[root] = 1; for (int e = head[root]; e != -1; e = edges[e].next) { int u = root, v = edges[e].v; if (visit[v]) continue; long long new_size_v = tree_size[u]; long long new_size_u = tree_size[u] - tree_size[v]; assert(("No zero", dp[v] != 0)); long long new_dp_u = dp[u] * fact_ret[tree_size[v]] % M * fact_ret[new_size_u - 1] % M * inv_mod(dp[v]) % M * inv_mod(fact_ret[tree_size[u] - 1]) % M; long long new_dp_v = dp[v] * new_dp_u % M * fact_ret[new_size_v - 1] % M * inv_mod(fact_ret[new_size_u]) % M * inv_mod(fact_ret[tree_size[v] - 1]) % M; long long old_size_v = tree_size[v], old_size_u = tree_size[u], old_dp_u = dp[u], old_dp_v = dp[v]; ans[v] = new_dp_v; dp[u] = new_dp_u; dp[v] = new_dp_v; tree_size[u] = new_size_u; tree_size[v] = new_size_v; // cout << root << ' ' << v << ' ' << new_dp_u << ' ' << new_dp_v << endl; root_transfer(v); dp[u] = old_dp_u; dp[v] = old_dp_v; tree_size[u] = old_size_u; tree_size[v] = old_size_u; } } int main() { memset(head, -1, sizeof(head)); memset(dp, 0, sizeof(dp)); memset(fact_ret, -1, sizeof(fact_ret)); int n; cin >> n; for (int i = 0; i < n - 1; ++i) { int a, b; cin >> a >> b; add(a, b); add(b, a); } cal_fact(); memset(visit, 0, sizeof(visit)); memset(tree_size, 0, sizeof(tree_size)); cal_size(1); memset(dp, 0, sizeof(dp)); memset(visit, 0, sizeof(visit)); cal_dp(1); ans[1] = dp[1]; memset(visit, 0, sizeof(visit)); root_transfer(1); for (int i = 1; i <= n; ++i) cout << ans[i] << endl; return 0; }
replace
77
78
77
78
0
p02728
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef std::vector<int> vi; typedef std::vector<std::vector<int>> vvi; typedef std::vector<long long> vl; typedef std::vector<std::vector<long long>> vvl; #define out(x) cout << x << "\n"; using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); // gl=xy } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } }; vector<vector<int>> g; Combination<modint> c(1e5); struct DP { modint dp; // 塗り方 int t; // 部分木のサイズ DP(modint dp = 1, int t = 0) : dp(dp), t(t) {} DP &operator+=(const DP &a) { // 演算をまとめて表す dp *= a.dp; // この時点では根を含まない dp *= c.C(t + a.t, t); t += a.t; return *this; } DP operator-(const DP &a) const { DP res(*this); res.t -= a.t; res.dp /= c.C(res.t + a.t, res.t); res.dp /= a.dp; return res; } DP addRoot() const { DP res(*this); res.t++; return res; } }; vector<DP> dp; void dfs(int v, int par = -1) { for (int x : g[v]) { if (x == par) continue; dfs(x, v); dp[v] += dp[x].addRoot(); } } void bfs(int v, int par = -1) { for (int u : g[v]) { if (u == par) continue; DP d = dp[v] - dp[u].addRoot(); dp[u] += d.addRoot(); bfs(u, v); } } void solve() { int n; cin >> n; g.resize(n); dp.resize(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; g[a].pb(b); g[b].pb(a); } dfs(0); bfs(0); rep(i, n) cout << dp[i].addRoot().dp << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <stack> #include <string> #include <unordered_set> #include <vector> #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef std::vector<int> vi; typedef std::vector<std::vector<int>> vvi; typedef std::vector<long long> vl; typedef std::vector<std::vector<long long>> vvl; #define out(x) cout << x << "\n"; using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll INF = 1LL << 60; ll gcd(ll n, ll m) { ll tmp; while (m != 0) { tmp = n % m; n = m; m = tmp; } return n; } ll lcm(ll n, ll m) { return abs(n) / gcd(n, m) * abs(m); // gl=xy } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; template <typename T> struct Combination { vector<T> _fact, _rfact, _inv; Combination(int sz) : _fact(sz + 1), _rfact(sz + 1), _inv(sz + 1) { _fact[0] = _rfact[sz] = _inv[0] = 1; for (int i = 1; i <= sz; i++) _fact[i] = _fact[i - 1] * i; _rfact[sz] /= _fact[sz]; for (int i = sz - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1); for (int i = 1; i <= sz; i++) _inv[i] = _rfact[i] * _fact[i - 1]; } inline T fact(int k) const { return _fact[k]; } inline T rfact(int k) const { return _rfact[k]; } inline T inv(int k) const { return _inv[k]; } T P(int n, int r) const { if (r < 0 || n < r) return 0; return fact(n) * rfact(n - r); } T C(int p, int q) const { if (q < 0 || p < q) return 0; return fact(p) * rfact(q) * rfact(p - q); } T H(int n, int r) const { if (n < 0 || r < 0) return (0); return r == 0 ? 1 : C(n + r - 1, r); } }; vector<vector<int>> g; Combination<modint> c(3e5); struct DP { modint dp; // 塗り方 int t; // 部分木のサイズ DP(modint dp = 1, int t = 0) : dp(dp), t(t) {} DP &operator+=(const DP &a) { // 演算をまとめて表す dp *= a.dp; // この時点では根を含まない dp *= c.C(t + a.t, t); t += a.t; return *this; } DP operator-(const DP &a) const { DP res(*this); res.t -= a.t; res.dp /= c.C(res.t + a.t, res.t); res.dp /= a.dp; return res; } DP addRoot() const { DP res(*this); res.t++; return res; } }; vector<DP> dp; void dfs(int v, int par = -1) { for (int x : g[v]) { if (x == par) continue; dfs(x, v); dp[v] += dp[x].addRoot(); } } void bfs(int v, int par = -1) { for (int u : g[v]) { if (u == par) continue; DP d = dp[v] - dp[u].addRoot(); dp[u] += d.addRoot(); bfs(u, v); } } void solve() { int n; cin >> n; g.resize(n); dp.resize(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; g[a].pb(b); g[b].pb(a); } dfs(0); bfs(0); rep(i, n) cout << dp[i].addRoot().dp << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }
replace
189
190
189
190
0
p02728
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long ll; long long inv(int a, int p) { return a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p; } static const int MODVAL = 1000000007; struct mint { int val; mint() : val(0) {} mint(int x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint(size_t x) : val(x % MODVAL) {} mint(long long x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint &operator+=(mint y) { val += y.val; if (val >= MODVAL) val -= MODVAL; return *this; } mint &operator-=(mint y) { val -= y.val; if (val < 0) val += MODVAL; return *this; } mint &operator*=(mint y) { val = (val * (long long)y.val) % MODVAL; return *this; } mint &operator/=(mint y) { val = (val * inv(y.val, MODVAL)) % MODVAL; return *this; } }; inline mint operator+(mint x, mint y) { return x += y; } inline mint operator-(mint x, mint y) { return x -= y; } inline mint operator*(mint x, mint y) { return x *= y; } inline mint operator/(mint x, mint y) { return x /= y; } mint POW(mint x, long long n) { mint r(1); for (; n; x *= x, n >>= 1) if (n & 1) r *= x; return r; } mint FAC(int n) { static vector<mint> FAC_(1, 1); while (int(FAC_.size()) <= n) FAC_.push_back(FAC_.back() * FAC_.size()); return FAC_[n]; } inline mint CMB(int n, int k) { return k < 0 || n < k ? 0 : FAC(n) / (FAC(k) * FAC(n - k)); } inline ostream &operator<<(ostream &os, mint a) { return os << a.val; } int n; vector<int> g[200000 + 5]; struct K { mint v; int count; }; map<ll, K> memo; K solve(int p, int u) { ll key = (ll(p) << 32LL) | u; if (memo.count(key) == 0) { K res; res.v = 1; res.count = 1; vector<int> counts; for (int v : g[u]) { if (v == p) { continue; } K cur = solve(u, v); res.v *= cur.v; counts.push_back(cur.count); res.count += cur.count; } int cc = res.count - 1; for (int c : counts) { res.v *= CMB(cc, c); cc -= c; } memo[key] = res; } return memo[key]; } mint ans[200000 + 10]; void propagate(int p, int u, mint pval, int pcount) { mint res = 1; vector<int> counts; for (int v : g[u]) { if (v == p) { res *= pval; counts.push_back(pcount); } else { K cur = solve(u, v); res *= cur.v; counts.push_back(cur.count); } } int cc = n - 1; for (int c : counts) { res *= CMB(cc, c); cc -= c; } ans[u] = res; for (int v : g[u]) { if (v == p) { continue; } K cur = solve(u, v); propagate(u, v, res / cur.v / CMB(n - 1, cur.count), n - cur.count); } } int main(void) { scanf("%d", &n); REP(i, n - 1) { int a, b; scanf("%d%d", &a, &b); --a; --b; g[a].push_back(b); g[b].push_back(a); } solve(1000000000, 0); propagate(1000000000, 0, 1, 0); REP(u, n) { K res; res.v = 1; res.count = 1; vector<int> counts; for (int v : g[u]) { K cur = solve(u, v); res.v *= cur.v; res.count += cur.count; counts.push_back(cur.count); } int cc = res.count - 1; for (int c : counts) { res.v *= CMB(cc, c); cc -= c; } printf("%d\n", res.v.val); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) typedef long long ll; long long inv(int a, int p) { return a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p; } static const int MODVAL = 1000000007; struct mint { int val; mint() : val(0) {} mint(int x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint(size_t x) : val(x % MODVAL) {} mint(long long x) : val(x % MODVAL) { if (val < 0) val += MODVAL; } mint &operator+=(mint y) { val += y.val; if (val >= MODVAL) val -= MODVAL; return *this; } mint &operator-=(mint y) { val -= y.val; if (val < 0) val += MODVAL; return *this; } mint &operator*=(mint y) { val = (val * (long long)y.val) % MODVAL; return *this; } mint &operator/=(mint y) { val = (val * inv(y.val, MODVAL)) % MODVAL; return *this; } }; inline mint operator+(mint x, mint y) { return x += y; } inline mint operator-(mint x, mint y) { return x -= y; } inline mint operator*(mint x, mint y) { return x *= y; } inline mint operator/(mint x, mint y) { return x /= y; } mint POW(mint x, long long n) { mint r(1); for (; n; x *= x, n >>= 1) if (n & 1) r *= x; return r; } mint FAC(int n) { static vector<mint> FAC_(1, 1); while (int(FAC_.size()) <= n) FAC_.push_back(FAC_.back() * FAC_.size()); return FAC_[n]; } inline mint CMB(int n, int k) { return k < 0 || n < k ? 0 : FAC(n) / (FAC(k) * FAC(n - k)); } inline ostream &operator<<(ostream &os, mint a) { return os << a.val; } int n; vector<int> g[200000 + 5]; struct K { mint v; int count; }; map<ll, K> memo; K solve(int p, int u) { ll key = (ll(p) << 32LL) | u; if (memo.count(key) == 0) { K res; res.v = 1; res.count = 1; vector<int> counts; for (int v : g[u]) { if (v == p) { continue; } K cur = solve(u, v); res.v *= cur.v; counts.push_back(cur.count); res.count += cur.count; } int cc = res.count - 1; for (int c : counts) { res.v *= CMB(cc, c); cc -= c; } memo[key] = res; } return memo[key]; } mint ans[200000 + 10]; void propagate(int p, int u, mint pval, int pcount) { mint res = 1; vector<int> counts; for (int v : g[u]) { if (v == p) { res *= pval; counts.push_back(pcount); } else { K cur = solve(u, v); res *= cur.v; counts.push_back(cur.count); } } int cc = n - 1; for (int c : counts) { res *= CMB(cc, c); cc -= c; } ans[u] = res; for (int v : g[u]) { if (v == p) { continue; } K cur = solve(u, v); propagate(u, v, res / cur.v / CMB(n - 1, cur.count), n - cur.count); } } int main(void) { scanf("%d", &n); REP(i, n - 1) { int a, b; scanf("%d%d", &a, &b); --a; --b; g[a].push_back(b); g[b].push_back(a); } solve(1000000000, 0); propagate(1000000000, 0, 1, 0); REP(u, n) { printf("%d\n", ans[u].val); } return 0; }
replace
147
165
147
148
TLE
p02728
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pll = pair<ll, ll>; constexpr int MOD = 1000000007; int main() { int N; cin >> N; vector<vector<int>> G(N); for (int i = 0; i < N - 1; ++i) { int a, b; cin >> a >> b; G[a - 1].push_back(b - 1); G[b - 1].push_back(a - 1); } vector<ll> fact(N), factinv(N), inv(N); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i < N; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } function<ll(ll)> modinv = [&](ll x) { ll b = MOD, u = 1, v = 0; while (b) { ll t = x / b; x -= t * b; u -= t * v; swap(x, b); swap(u, v); } return (u + MOD) % MOD; }; vector<map<int, Pll>> dp(N); function<Pll(int, int)> dfs = [&](int u, int par) { if (!dp[u].count(par)) { Pll ret = {1, 1}; if (!dp[u].count(-1)) { for (int v : G[u]) { if (v != par) { Pll t = dfs(v, u); ret.first += t.first; ret.second = ret.second * t.second % MOD; ret.second = ret.second * factinv[t.first] % MOD; } } ret.second = ret.second * fact[ret.first - 1] % MOD; } else { ret = dp[u][-1]; Pll t = dfs(par, u); ret.second = ret.second * factinv[ret.first - 1] % MOD; ret.second = ret.second * fact[t.first] % MOD; ret.first -= t.first; ret.second = ret.second * fact[ret.first - 1] % MOD; ret.second = ret.second * modinv(t.second) % MOD; } dp[u][par] = ret; } return dp[u][par]; }; vector<ll> id(N), ans(N); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&](const int &l, const int &r) { return G[l] > G[r]; }); for (int i = 0; i < N; ++i) ans[id[i]] = dfs(id[i], -1).second; for (int i = 0; i < N; ++i) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Pll = pair<ll, ll>; constexpr int MOD = 1000000007; int main() { int N; cin >> N; vector<vector<int>> G(N); for (int i = 0; i < N - 1; ++i) { int a, b; cin >> a >> b; G[a - 1].push_back(b - 1); G[b - 1].push_back(a - 1); } vector<ll> fact(N), factinv(N), inv(N); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i < N; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } function<ll(ll)> modinv = [&](ll x) { ll b = MOD, u = 1, v = 0; while (b) { ll t = x / b; x -= t * b; u -= t * v; swap(x, b); swap(u, v); } return (u + MOD) % MOD; }; vector<map<int, Pll>> dp(N); function<Pll(int, int)> dfs = [&](int u, int par) { if (!dp[u].count(par)) { Pll ret = {1, 1}; if (!dp[u].count(-1)) { for (int v : G[u]) { if (v != par) { Pll t = dfs(v, u); ret.first += t.first; ret.second = ret.second * t.second % MOD; ret.second = ret.second * factinv[t.first] % MOD; } } ret.second = ret.second * fact[ret.first - 1] % MOD; } else { ret = dp[u][-1]; Pll t = dfs(par, u); ret.second = ret.second * factinv[ret.first - 1] % MOD; ret.second = ret.second * fact[t.first] % MOD; ret.first -= t.first; ret.second = ret.second * fact[ret.first - 1] % MOD; ret.second = ret.second * modinv(t.second) % MOD; } dp[u][par] = ret; } return dp[u][par]; }; vector<ll> id(N), ans(N); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&](const int &l, const int &r) { return G[l].size() > G[r].size(); }); for (int i = 0; i < N; ++i) ans[id[i]] = dfs(id[i], -1).second; for (int i = 0; i < N; ++i) cout << ans[i] << endl; return 0; }
replace
67
68
67
68
TLE
p02728
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef vector<ll> vint; typedef vector<vector<ll>> vvint; typedef vector<vector<vector<ll>>> vvvint; typedef vector<string> vstring; typedef vector<vector<string>> vvstring; typedef vector<char> vchar; typedef vector<vector<char>> vvchar; typedef vector<long double> vdouble; typedef vector<vector<long double>> vvdouble; typedef vector<vector<vector<long double>>> vvvdouble; typedef pair<ll, ll> pint; typedef vector<pint> vpint; typedef vector<bool> vbool; #define rep(i, n) for (ll i = 0; i < n; i++) #define repf(i, f, n) for (ll i = f; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define mp make_pair #define mt make_tuple #define pb push_back #define pf push_front #define fi first #define se second #define ALL(obj) (obj).begin(), (obj).end() // #define LLONG_MAX 9223372036854775806 #define vmax(vec) *max_element(vec.begin(), vec.end()) #define vmin(vec) *min_element(vec.begin(), vec.end()) #define vsort(vec) sort(vec.begin(), vec.end()) #define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>()) #define MOD 1000000007 // #define MOD 998244353 // #define MOD LLONG_MAX const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int dy[] = {0, 0, 1, -1}; int dx[] = { 1, -1, 0, 0, }; void printv(vint &v) { for (auto e : v) cout << e << " "; cout << endl; } // 繰り返し二乗法 ll power(ll a, ll b) { if (a == 1) return a; // if(a==0)re ll res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } const int MAX = 2100000; ll fact[MAX], fact_inv[MAX]; void init_fact(ll n) { fact[0] = 1; // 階乗の計算 for (ll i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD; fact_inv[n] = power(fact[n], MOD - 2); // 逆元の計算 for (ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; } ll comb(ll n, ll r) { return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD; } ll perm(ll n, ll r) { return (fact[n] * fact_inv[n - r]) % MOD; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<(int)(1e9 + 7)>; ll n; vvint edges; map<pint, pair<ll, modint>> dp; void treeDP(ll src, ll to) { if (dp.count(mp(src, to))) return; ll x; modint y; if (dp.count(mp(0, to))) { // puts("yay"); // cout<<src<<" "<<to<<endl; // cout<<dp[mp(0,to)].first<<" "<<dp[mp(0,to)].second<<endl; tie(x, y) = dp[mp(0, to)]; y *= fact_inv[n - 1]; y *= fact[n - 1 - dp[mp(to, src)].first]; y *= fact[dp[mp(to, src)].first]; y /= dp[mp(to, src)].second; x = n - dp[mp(to, src)].first; // cout<<x<<" "<<y<<endl<<endl; } else { x = 0; y = 1; for (auto e : edges[to]) { if (e == src) continue; if (dp.count(mp(to, e)) == 0) treeDP(to, e); ll dx; modint dy; tie(dx, dy) = dp[mp(to, e)]; x += dx; y *= dy; y *= fact_inv[dx]; } y *= fact[x]; x++; } dp[mp(src, to)] = mp(x, y); } int main() { cout << fixed << setprecision(10); cin >> n; edges.resize(n + 1); rep(i, n - 1) { ll a, b; cin >> a >> b; edges[a].push_back(b); edges[b].push_back(a); } init_fact(2e5 + 100); rep(i, n) { treeDP(0, i + 1); cout << dp[mp(0, i + 1)].second << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef vector<ll> vint; typedef vector<vector<ll>> vvint; typedef vector<vector<vector<ll>>> vvvint; typedef vector<string> vstring; typedef vector<vector<string>> vvstring; typedef vector<char> vchar; typedef vector<vector<char>> vvchar; typedef vector<long double> vdouble; typedef vector<vector<long double>> vvdouble; typedef vector<vector<vector<long double>>> vvvdouble; typedef pair<ll, ll> pint; typedef vector<pint> vpint; typedef vector<bool> vbool; #define rep(i, n) for (ll i = 0; i < n; i++) #define repf(i, f, n) for (ll i = f; i < n; i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define mp make_pair #define mt make_tuple #define pb push_back #define pf push_front #define fi first #define se second #define ALL(obj) (obj).begin(), (obj).end() // #define LLONG_MAX 9223372036854775806 #define vmax(vec) *max_element(vec.begin(), vec.end()) #define vmin(vec) *min_element(vec.begin(), vec.end()) #define vsort(vec) sort(vec.begin(), vec.end()) #define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>()) #define MOD 1000000007 // #define MOD 998244353 // #define MOD LLONG_MAX const double PI = 3.14159265358979323846; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int dy[] = {0, 0, 1, -1}; int dx[] = { 1, -1, 0, 0, }; void printv(vint &v) { for (auto e : v) cout << e << " "; cout << endl; } // 繰り返し二乗法 ll power(ll a, ll b) { if (a == 1) return a; // if(a==0)re ll res = 1; while (b > 0) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } const int MAX = 2100000; ll fact[MAX], fact_inv[MAX]; void init_fact(ll n) { fact[0] = 1; // 階乗の計算 for (ll i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1) % MOD; fact_inv[n] = power(fact[n], MOD - 2); // 逆元の計算 for (ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD; } ll comb(ll n, ll r) { return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD; } ll perm(ll n, ll r) { return (fact[n] * fact_inv[n - r]) % MOD; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<(int)(1e9 + 7)>; ll n; vvint edges; map<pint, pair<ll, modint>> dp; void treeDP(ll src, ll to) { if (dp.count(mp(src, to))) return; ll x; modint y; if (dp.count(mp(0, to))) { // puts("yay"); // cout<<src<<" "<<to<<endl; // cout<<dp[mp(0,to)].first<<" "<<dp[mp(0,to)].second<<endl; tie(x, y) = dp[mp(0, to)]; y *= fact_inv[n - 1]; y *= fact[n - 1 - dp[mp(to, src)].first]; y *= fact[dp[mp(to, src)].first]; y /= dp[mp(to, src)].second; x = n - dp[mp(to, src)].first; // cout<<x<<" "<<y<<endl<<endl; } else { x = 0; y = 1; for (auto e : edges[to]) { if (e == src) continue; if (dp.count(mp(to, e)) == 0) treeDP(to, e); ll dx; modint dy; tie(dx, dy) = dp[mp(to, e)]; x += dx; y *= dy; y *= fact_inv[dx]; } y *= fact[x]; x++; } dp[mp(src, to)] = mp(x, y); } int main() { cout << fixed << setprecision(10); cin >> n; edges.resize(n + 1); rep(i, n - 1) { ll a, b; cin >> a >> b; edges[a].push_back(b); edges[b].push_back(a); } init_fact(2e5 + 100); queue<ll> q; q.push(1); set<ll> used; while (!q.empty()) { ll src = q.front(); q.pop(); if (used.count(src)) continue; used.insert(src); treeDP(0, src); for (auto to : edges[src]) { if (used.count(to)) continue; q.push(to); } } rep(i, n) { cout << dp[mp(0, i + 1)].second << endl; } return 0; }
replace
236
240
236
254
TLE
p02728
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second // #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 200020; vector<ll> fact(MAX), ifac(MAX); vector<ll> invs(MAX); vector<vector<int>> g(MAX); vector<ll> dp(MAX); vector<ll> sz(MAX); ll pwr(ll a, ll n) { if (n == 0) return 1; if (n == 1) return a % mod; ll q = pwr(a, n >> 1); q = 1ll * q * q % mod; if (n & 1) q = 1ll * q * a % mod; return q; } ll inv(ll n) { return pwr(n, mod - 2); } void init() { fact[0] = 1, invs[1] = 1, ifac[0] = 1; for (int i = 1; i < MAX; i++) fact[i] = 1ll * fact[i - 1] * i % mod; for (int i = 2; i < MAX; i++) invs[i] = -invs[mod % i] * 1ll * (mod / i) % mod; for (int i = 1; i < MAX; i++) ifac[i] = 1ll * ifac[i - 1] * invs[i] % mod; } void dfs1(int v, int p = -1) { dp[v] = 1; sz[v] = 1; for (int u : g[v]) { if (u == p) continue; dfs1(u, v); sz[v] += sz[u]; dp[v] = (1ll * dp[v] * dp[u] % mod) * ifac[sz[u]] % mod; } dp[v] = 1ll * dp[v] * fact[sz[v] - 1] % mod; } void dfs2(int v, int p = -1) { for (int u : g[v]) { if (u == p) continue; ll tmp = (dp[v] * fact[sz[u]] % mod) % mod; tmp = fact[sz[1] - sz[u] - 1] * tmp % mod; ll tmp_n = ifac[sz[u] - 1] % mod; dp[u] = tmp_n * tmp % mod; dp[u] = dp[u] * ifac[sz[1] - sz[u]] % mod; dfs2(u, v); } } void solve() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs1(1); // cout << dp[1] + mod << "\n"; dfs2(1); for (int i = 1; i <= n; i++) { cout << (dp[i] + mod) % mod << "\n"; } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; init(); while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 200020; vector<ll> fact(MAX), ifac(MAX); vector<ll> invs(MAX); vector<vector<int>> g(MAX); vector<ll> dp(MAX); vector<ll> sz(MAX); ll pwr(ll a, ll n) { if (n == 0) return 1; if (n == 1) return a % mod; ll q = pwr(a, n >> 1); q = 1ll * q * q % mod; if (n & 1) q = 1ll * q * a % mod; return q; } ll inv(ll n) { return pwr(n, mod - 2); } void init() { fact[0] = 1, invs[1] = 1, ifac[0] = 1; for (int i = 1; i < MAX; i++) fact[i] = 1ll * fact[i - 1] * i % mod; for (int i = 2; i < MAX; i++) invs[i] = -invs[mod % i] * 1ll * (mod / i) % mod; for (int i = 1; i < MAX; i++) ifac[i] = 1ll * ifac[i - 1] * invs[i] % mod; } void dfs1(int v, int p = -1) { dp[v] = 1; sz[v] = 1; for (int u : g[v]) { if (u == p) continue; dfs1(u, v); sz[v] += sz[u]; dp[v] = (1ll * dp[v] * dp[u] % mod) * ifac[sz[u]] % mod; } dp[v] = 1ll * dp[v] * fact[sz[v] - 1] % mod; } void dfs2(int v, int p = -1) { for (int u : g[v]) { if (u == p) continue; ll tmp = (dp[v] * fact[sz[u]] % mod) % mod; tmp = fact[sz[1] - sz[u] - 1] * tmp % mod; ll tmp_n = ifac[sz[u] - 1] % mod; dp[u] = tmp_n * tmp % mod; dp[u] = dp[u] * ifac[sz[1] - sz[u]] % mod; dfs2(u, v); } } void solve() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs1(1); // cout << dp[1] + mod << "\n"; dfs2(1); for (int i = 1; i <= n; i++) { cout << (dp[i] + mod) % mod << "\n"; } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; init(); while (t--) solve(); return 0; }
replace
7
8
7
8
-6
munmap_chunk(): invalid pointer
p02728
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second // #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 200020; vector<ll> fact(MAX), ifac(MAX); vector<ll> invs(MAX); vector<vector<int>> g(MAX); vector<ll> dp(MAX); vector<ll> sz(MAX); ll pwr(ll a, ll n) { if (n == 0) return 1; if (n == 1) return a % mod; ll q = pwr(a, n >> 1); q = 1ll * q * q % mod; if (n & 1) q = 1ll * q * a % mod; return q; } ll inv(ll n) { return pwr(n, mod - 2); } void init() { fact[0] = 1, invs[1] = 1, ifac[0] = 1; for (int i = 1; i < MAX; i++) fact[i] = 1ll * fact[i - 1] * i % mod; for (int i = 2; i < MAX; i++) invs[i] = -invs[mod % i] * 1ll * (mod / i) % mod; for (int i = 1; i < MAX; i++) ifac[i] = 1ll * ifac[i - 1] * invs[i] % mod; } void dfs1(int v, int p = -1) { dp[v] = 1; sz[v] = 1; for (int u : g[v]) { if (u == p) continue; dfs1(u, v); sz[v] += sz[u]; dp[v] = (1ll * dp[v] * dp[u] % mod) * ifac[sz[u]] % mod; } dp[v] = 1ll * dp[v] * fact[sz[v] - 1] % mod; } void dfs2(int v, int p = -1) { for (int u : g[v]) { if (u == p) continue; ll tmp = (dp[v] * fact[sz[u]] % mod) * inv(dp[u]) % mod; tmp = ifac[sz[1] - 1] * tmp % mod; tmp = fact[sz[1] - sz[u] - 1] * tmp % mod; ll tmp_n = ifac[sz[u] - 1] * dp[u] % mod; tmp_n = tmp_n * fact[sz[1] - 1] % mod; dp[u] = tmp_n * tmp % mod; dp[u] = dp[u] * ifac[sz[1] - sz[u]] % mod; dfs2(u, v); } } void solve() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs1(1); // cout << dp[1] + mod << "\n"; dfs2(1); for (int i = 1; i <= n; i++) { cout << (dp[i] + mod) % mod << "\n"; } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; init(); while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define F first #define S second #define ONLINE_JUDGE 1 using namespace std; const int mod = 1e9 + 7; const int MAX = 200020; vector<ll> fact(MAX), ifac(MAX); vector<ll> invs(MAX); vector<vector<int>> g(MAX); vector<ll> dp(MAX); vector<ll> sz(MAX); ll pwr(ll a, ll n) { if (n == 0) return 1; if (n == 1) return a % mod; ll q = pwr(a, n >> 1); q = 1ll * q * q % mod; if (n & 1) q = 1ll * q * a % mod; return q; } ll inv(ll n) { return pwr(n, mod - 2); } void init() { fact[0] = 1, invs[1] = 1, ifac[0] = 1; for (int i = 1; i < MAX; i++) fact[i] = 1ll * fact[i - 1] * i % mod; for (int i = 2; i < MAX; i++) invs[i] = -invs[mod % i] * 1ll * (mod / i) % mod; for (int i = 1; i < MAX; i++) ifac[i] = 1ll * ifac[i - 1] * invs[i] % mod; } void dfs1(int v, int p = -1) { dp[v] = 1; sz[v] = 1; for (int u : g[v]) { if (u == p) continue; dfs1(u, v); sz[v] += sz[u]; dp[v] = (1ll * dp[v] * dp[u] % mod) * ifac[sz[u]] % mod; } dp[v] = 1ll * dp[v] * fact[sz[v] - 1] % mod; } void dfs2(int v, int p = -1) { for (int u : g[v]) { if (u == p) continue; ll tmp = (dp[v] * fact[sz[u]] % mod) * inv(dp[u]) % mod; tmp = ifac[sz[1] - 1] * tmp % mod; tmp = fact[sz[1] - sz[u] - 1] * tmp % mod; ll tmp_n = ifac[sz[u] - 1] * dp[u] % mod; tmp_n = tmp_n * fact[sz[1] - 1] % mod; dp[u] = tmp_n * tmp % mod; dp[u] = dp[u] * ifac[sz[1] - sz[u]] % mod; dfs2(u, v); } } void solve() { int n; cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } dfs1(1); // cout << dp[1] + mod << "\n"; dfs2(1); for (int i = 1; i <= n; i++) { cout << (dp[i] + mod) % mod << "\n"; } } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int t = 1; // cin >> t; init(); while (t--) solve(); return 0; }
replace
7
8
7
8
-6
munmap_chunk(): invalid pointer
p02728
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int pw(int x, int y) { int r = 1; while (y) { if (y & 1) r = 1ll * r * x % mod; x = 1ll * x * x % mod; y >>= 1; } return r; } int inv(int x) { return pw(x, mod - 2); } int n; vector<int> adj[200005]; int dad[200005]; int sz[120005]; int ans[200005]; int add = 1; void dfs(int u) { sz[u] = 1; for (auto v : adj[u]) { if (v == dad[u]) continue; dad[v] = u; dfs(v); sz[u] += sz[v]; } add = 1ll * add * inv(sz[u]) % mod; } void dfs2(int u) { ans[u] = add; for (auto v : adj[u]) { if (v == dad[u]) continue; int save = add; add = 1ll * add * sz[v] % mod; add = 1ll * add * inv(n - sz[v]) % mod; dfs2(v); add = save; } } int main(void) { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; ++i) add = 1ll * add * i % mod; dfs(1); dfs2(1); for (int i = 1; i <= n; i++) cout << ans[i] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int pw(int x, int y) { int r = 1; while (y) { if (y & 1) r = 1ll * r * x % mod; x = 1ll * x * x % mod; y >>= 1; } return r; } int inv(int x) { return pw(x, mod - 2); } int n; vector<int> adj[200005]; int dad[200005]; int sz[200005]; int ans[200005]; int add = 1; void dfs(int u) { sz[u] = 1; for (auto v : adj[u]) { if (v == dad[u]) continue; dad[v] = u; dfs(v); sz[u] += sz[v]; } add = 1ll * add * inv(sz[u]) % mod; } void dfs2(int u) { ans[u] = add; for (auto v : adj[u]) { if (v == dad[u]) continue; int save = add; add = 1ll * add * sz[v] % mod; add = 1ll * add * inv(n - sz[v]) % mod; dfs2(v); add = save; } } int main(void) { ios_base::sync_with_stdio(0); cin.tie(NULL); cin >> n; for (int i = 1; i < n; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; ++i) add = 1ll * add * i % mod; dfs(1); dfs2(1); for (int i = 1; i <= n; i++) cout << ans[i] << "\n"; return 0; }
replace
21
22
21
22
0
p02728
C++
Runtime Error
// #include "pch.h" #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define ll long long #define fri(n) for (i = 0; i < (n); i++) #define frj(n) for (j = 0; j < (n); i++) #define min(p, q) ((p) < (q) ? (p) : (q)) #define max(p, q) ((p) > (q) ? (p) : (q)) #define INF 1000000000000000000 // 10^18 #define INFINT 2000000001 // 2*10^9+1 #define MOD 1000000007 #define MODANOTHER 998244353 #define PI acos(-1) #define vi vector<int> #define vvi vector<vector<int>> #define vvvi vector<vector<vector<int>>> #define vd vector<double> #define vvd vector<vector<double>> #define vvvd vector<vector<vector<double>>> #define int long long using namespace std; const int MAX = 510000; ll mod_inverse(int a, int M) { int x = M - 2; ll temp = a; ll ret = 1; // a^(MOD-1)==1(mod MOD)を利用 // a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める while (x != 0) { if (x % 2 == 1) { ret = (ret * temp) % M; } temp = (temp * temp) % M; x = x / 2; } return ret; } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } signed compare_ll(const void *a, const void *b) { ll *A = (ll *)a; ll *B = (ll *)b; if (*A < *B) return 1; if (*A > *B) return -1; return 0; } int makeGraph(int x, vvi &gtemp, vvi &graph, vi &come) { int i; come[x] = 1; for (i = 0; i < gtemp[x].size(); i++) { if (come[gtemp[x][i]] == 1) continue; graph[x].push_back(gtemp[x][i]); makeGraph(gtemp[x][i], gtemp, graph, come); } return 0; } struct pret_t { int vertex; int patan; }; pret_t search(int x, vvi &graph, vector<vector<pret_t>> &vvpret) { int i; int temp; int sum; pret_t pret; pret_t ptemp; vector<pret_t> vptemp; for (i = 0; i < graph[x].size(); i++) { ptemp = search(graph[x][i], graph, vvpret); vptemp.push_back(ptemp); } vvpret[x] = vptemp; pret.vertex = 1; pret.patan = 1; for (i = 0; i < vptemp.size(); i++) { pret.vertex += vptemp[i].vertex; } temp = pret.vertex - 1; for (i = 0; i < vptemp.size(); i++) { pret.patan *= COM(temp, vptemp[i].vertex); pret.patan %= MOD; pret.patan *= vptemp[i].patan; pret.patan %= MOD; temp -= vptemp[i].vertex; } return pret; } int inverse(int x, pret_t prev, vi &vans, vvi &graph, vector<vector<pret_t>> &vvpret) { int i; int temp; pret_t pret; pret_t ptemp; vector<pret_t> vptemp; vptemp = vvpret[x]; if (x != 1) vptemp.push_back(prev); pret.vertex = 1; pret.patan = 1; for (i = 0; i < vptemp.size(); i++) { pret.vertex += vptemp[i].vertex; } temp = pret.vertex - 1; for (i = 0; i < vptemp.size(); i++) { pret.patan *= COM(temp, vptemp[i].vertex); pret.patan %= MOD; pret.patan *= vptemp[i].patan; pret.patan %= MOD; temp -= vptemp[i].vertex; } vans[x] = pret.patan; for (i = 0; i < graph[x].size(); i++) { ptemp.vertex = pret.vertex - vptemp[i].vertex; ptemp.patan = pret.patan * mod_inverse(COM(pret.vertex - 1, vptemp[i].vertex), MOD); ptemp.patan %= MOD; ptemp.patan = ptemp.patan * mod_inverse(vptemp[i].patan, MOD); ptemp.patan %= MOD; inverse(graph[x][i], ptemp, vans, graph, vvpret); } return 0; } signed main(void) { // 変数の宣言 int n, m; int h, w; int x, y; static int a[100010]; static int b[100010]; static int v[100010]; static int p[100010]; // よく使う変数 int i, j, k, l; int flag = 0; int ans = 0; int count = 0; int temp = 0; int temp1 = 0; int temp2 = 0; int temp3 = 0; vector<int> vec; vector<int> vtemp; int max = 0; int min = INFINT; int len = 0; int sum = 0; int ok = 0; int ng = 0; char dummy; static char stemp[100010]; vvi graph; // データの読み込み scanf("%lld", &n); // scanf_s("%lld",&n); // scanf("%s",&s); // scanf_s("%s",&s,20); for (i = 0; i < n - 1; i++) { scanf("%lld %lld", &a[i], &b[i]); // scanf_s("%lld %lld",&a[i],&b[i]); } // printf("nは%dです\n", n); // printf("データの読み込み終了\n"); // 実際の処理 // clock_t start=clock(); COMinit(); vvi gtemp; vi come(n + 1, 0); for (i = 0; i <= n; i++) { graph.push_back(vtemp); gtemp.push_back(vtemp); } for (i = 0; i < n - 1; i++) { gtemp[a[i]].push_back(b[i]); gtemp[b[i]].push_back(a[i]); } makeGraph(1, gtemp, graph, come); fill(come.begin(), come.end(), 0); // comeは多分もう使わない? pret_t ptemp; vector<pret_t> vpret; vector<vector<pret_t>> vvpret(n + 1, vpret); ptemp = search(1, graph, vvpret); // printf("%lld",ptemp.patan); vi vans(n + 1, 0); inverse(1, ptemp, vans, graph, vvpret); for (i = 1; i <= n; i++) { printf("%lld\n", vans[i]); } // clock_t end=clock(); // printf("計算部分終了\n"); // 出力 // printf("%d",(d[i-1][j-1]+1)/2); // printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC); // printf("結果の出力終了\n"); return 0; }
// #include "pch.h" #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <algorithm> #include <bitset> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> #define ll long long #define fri(n) for (i = 0; i < (n); i++) #define frj(n) for (j = 0; j < (n); i++) #define min(p, q) ((p) < (q) ? (p) : (q)) #define max(p, q) ((p) > (q) ? (p) : (q)) #define INF 1000000000000000000 // 10^18 #define INFINT 2000000001 // 2*10^9+1 #define MOD 1000000007 #define MODANOTHER 998244353 #define PI acos(-1) #define vi vector<int> #define vvi vector<vector<int>> #define vvvi vector<vector<vector<int>>> #define vd vector<double> #define vvd vector<vector<double>> #define vvvd vector<vector<vector<double>>> #define int long long using namespace std; const int MAX = 510000; ll mod_inverse(int a, int M) { int x = M - 2; ll temp = a; ll ret = 1; // a^(MOD-1)==1(mod MOD)を利用 // a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める while (x != 0) { if (x % 2 == 1) { ret = (ret * temp) % M; } temp = (temp * temp) % M; x = x / 2; } return ret; } long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } signed compare_ll(const void *a, const void *b) { ll *A = (ll *)a; ll *B = (ll *)b; if (*A < *B) return 1; if (*A > *B) return -1; return 0; } int makeGraph(int x, vvi &gtemp, vvi &graph, vi &come) { int i; come[x] = 1; for (i = 0; i < gtemp[x].size(); i++) { if (come[gtemp[x][i]] == 1) continue; graph[x].push_back(gtemp[x][i]); makeGraph(gtemp[x][i], gtemp, graph, come); } return 0; } struct pret_t { int vertex; int patan; }; pret_t search(int x, vvi &graph, vector<vector<pret_t>> &vvpret) { int i; int temp; int sum; pret_t pret; pret_t ptemp; vector<pret_t> vptemp; for (i = 0; i < graph[x].size(); i++) { ptemp = search(graph[x][i], graph, vvpret); vptemp.push_back(ptemp); } vvpret[x] = vptemp; pret.vertex = 1; pret.patan = 1; for (i = 0; i < vptemp.size(); i++) { pret.vertex += vptemp[i].vertex; } temp = pret.vertex - 1; for (i = 0; i < vptemp.size(); i++) { pret.patan *= COM(temp, vptemp[i].vertex); pret.patan %= MOD; pret.patan *= vptemp[i].patan; pret.patan %= MOD; temp -= vptemp[i].vertex; } return pret; } int inverse(int x, pret_t prev, vi &vans, vvi &graph, vector<vector<pret_t>> &vvpret) { int i; int temp; pret_t pret; pret_t ptemp; vector<pret_t> vptemp; vptemp = vvpret[x]; if (x != 1) vptemp.push_back(prev); pret.vertex = 1; pret.patan = 1; for (i = 0; i < vptemp.size(); i++) { pret.vertex += vptemp[i].vertex; } temp = pret.vertex - 1; for (i = 0; i < vptemp.size(); i++) { pret.patan *= COM(temp, vptemp[i].vertex); pret.patan %= MOD; pret.patan *= vptemp[i].patan; pret.patan %= MOD; temp -= vptemp[i].vertex; } vans[x] = pret.patan; for (i = 0; i < graph[x].size(); i++) { ptemp.vertex = pret.vertex - vptemp[i].vertex; ptemp.patan = pret.patan * mod_inverse(COM(pret.vertex - 1, vptemp[i].vertex), MOD); ptemp.patan %= MOD; ptemp.patan = ptemp.patan * mod_inverse(vptemp[i].patan, MOD); ptemp.patan %= MOD; inverse(graph[x][i], ptemp, vans, graph, vvpret); } return 0; } signed main(void) { // 変数の宣言 int n, m; int h, w; int x, y; static int a[200010]; static int b[200010]; static int v[100010]; static int p[100010]; // よく使う変数 int i, j, k, l; int flag = 0; int ans = 0; int count = 0; int temp = 0; int temp1 = 0; int temp2 = 0; int temp3 = 0; vector<int> vec; vector<int> vtemp; int max = 0; int min = INFINT; int len = 0; int sum = 0; int ok = 0; int ng = 0; char dummy; static char stemp[100010]; vvi graph; // データの読み込み scanf("%lld", &n); // scanf_s("%lld",&n); // scanf("%s",&s); // scanf_s("%s",&s,20); for (i = 0; i < n - 1; i++) { scanf("%lld %lld", &a[i], &b[i]); // scanf_s("%lld %lld",&a[i],&b[i]); } // printf("nは%dです\n", n); // printf("データの読み込み終了\n"); // 実際の処理 // clock_t start=clock(); COMinit(); vvi gtemp; vi come(n + 1, 0); for (i = 0; i <= n; i++) { graph.push_back(vtemp); gtemp.push_back(vtemp); } for (i = 0; i < n - 1; i++) { gtemp[a[i]].push_back(b[i]); gtemp[b[i]].push_back(a[i]); } makeGraph(1, gtemp, graph, come); fill(come.begin(), come.end(), 0); // comeは多分もう使わない? pret_t ptemp; vector<pret_t> vpret; vector<vector<pret_t>> vvpret(n + 1, vpret); ptemp = search(1, graph, vvpret); // printf("%lld",ptemp.patan); vi vans(n + 1, 0); inverse(1, ptemp, vans, graph, vvpret); for (i = 1; i <= n; i++) { printf("%lld\n", vans[i]); } // clock_t end=clock(); // printf("計算部分終了\n"); // 出力 // printf("%d",(d[i-1][j-1]+1)/2); // printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC); // printf("結果の出力終了\n"); return 0; }
replace
195
197
195
197
0
p02728
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define int long long #define endl "\n" #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb(x) push_back(x) #define MAXN 2020 typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vl; typedef vector<pii> vpi; typedef pair<ll, ll> pll; typedef vector<string> vs; typedef vector<pll> vpl; typedef vector<int> vi; inline int mod(int n, int m) { int ret = n % m; if (ret < 0) ret += m; return ret; } int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int exp(int a, int b, int m) { if (b == 0) return 1; if (b == 1) return mod(a, m); int k = mod(exp(a, b / 2, m), m); if (b & 1) { return mod(a * mod(k * k, m), m); } else return mod(k * k, m); } const int M = 1e9 + 7; vector<int> adj[MAXN]; int res[MAXN]; int dp[MAXN]; int sz[MAXN]; int fat[MAXN], inv[MAXN]; void dfs(int v, int p = -1) { sz[v] = 1; for (int x : adj[v]) { if (x == p) continue; dfs(x, v); sz[v] += sz[x]; } } int solve(int v, int p) { int ways = fat[sz[v] - 1]; for (int x : adj[v]) { if (x == p) continue; ways = mod(ways * mod(solve(x, v) * inv[sz[x]], M), M); } return dp[v] = ways; } int n; void solve2(int v, int p) { if (p == -1) { res[v] = dp[v]; } else { int dpp = mod(res[p], M); dpp = mod(dpp * fat[sz[v]], M); dpp = mod(dpp * exp(dp[v], M - 2, M), M); dpp = mod(dpp * fat[n - sz[v] - 1], M); dpp = mod(dpp * inv[n - sz[v]], M); res[v] = mod(dpp, M); for (int x : adj[v]) { if (x != p) { res[v] = mod(res[v] * mod(dp[x] * inv[sz[x]], M), M); } } } for (int x : adj[v]) { if (x == p) continue; solve2(x, v); } } int32_t main() { fastio; fat[0] = inv[0] = 1; for (int i = 1; i < MAXN; i++) { fat[i] = mod(fat[i - 1] * i, M); inv[i] = exp(fat[i], M - 2, M); } cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs(1, -1); solve(1, -1); solve2(1, -1); for (int i = 1; i <= n; i++) cout << res[i] << endl; // Math -> gcd it all // did you check N=1? Did you mix up N,M? }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define int long long #define endl "\n" #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb(x) push_back(x) #define MAXN 200100 typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vl; typedef vector<pii> vpi; typedef pair<ll, ll> pll; typedef vector<string> vs; typedef vector<pll> vpl; typedef vector<int> vi; inline int mod(int n, int m) { int ret = n % m; if (ret < 0) ret += m; return ret; } int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } int exp(int a, int b, int m) { if (b == 0) return 1; if (b == 1) return mod(a, m); int k = mod(exp(a, b / 2, m), m); if (b & 1) { return mod(a * mod(k * k, m), m); } else return mod(k * k, m); } const int M = 1e9 + 7; vector<int> adj[MAXN]; int res[MAXN]; int dp[MAXN]; int sz[MAXN]; int fat[MAXN], inv[MAXN]; void dfs(int v, int p = -1) { sz[v] = 1; for (int x : adj[v]) { if (x == p) continue; dfs(x, v); sz[v] += sz[x]; } } int solve(int v, int p) { int ways = fat[sz[v] - 1]; for (int x : adj[v]) { if (x == p) continue; ways = mod(ways * mod(solve(x, v) * inv[sz[x]], M), M); } return dp[v] = ways; } int n; void solve2(int v, int p) { if (p == -1) { res[v] = dp[v]; } else { int dpp = mod(res[p], M); dpp = mod(dpp * fat[sz[v]], M); dpp = mod(dpp * exp(dp[v], M - 2, M), M); dpp = mod(dpp * fat[n - sz[v] - 1], M); dpp = mod(dpp * inv[n - sz[v]], M); res[v] = mod(dpp, M); for (int x : adj[v]) { if (x != p) { res[v] = mod(res[v] * mod(dp[x] * inv[sz[x]], M), M); } } } for (int x : adj[v]) { if (x == p) continue; solve2(x, v); } } int32_t main() { fastio; fat[0] = inv[0] = 1; for (int i = 1; i < MAXN; i++) { fat[i] = mod(fat[i - 1] * i, M); inv[i] = exp(fat[i], M - 2, M); } cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs(1, -1); solve(1, -1); solve2(1, -1); for (int i = 1; i <= n; i++) cout << res[i] << endl; // Math -> gcd it all // did you check N=1? Did you mix up N,M? }
replace
17
18
17
18
0
p02728
C++
Runtime Error
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define FOE(i, a) for (auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) #define IS_BIT_ON(bit, i) (bit & (1 << i)) #define BIT_ON(bit, i) (bit |= (1 << i)) #define BIT_OFF(bit, i) (bit &= ~(1 << i)) #define BIT_COUNT(bit) (__builtin_popcount(bit)) typedef long long LL; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // C++14 template <typename T, typename V> typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename std::enable_if<std::is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class T> inline T ceil(T a, T b) { return (a + b - 1) / b; } void print() { std::cout << std::endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cout << head; if (sizeof...(tail) != 0) { std::cout << " "; } print(std::forward<Tail>(tail)...); } template <class T> void print(std::vector<T> &v) { for (auto &a : v) { std::cout << a; if (&a != &v.back()) { std::cout << " "; } } std::cout << std::endl; } template <class T> void print(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); } } void debug() { std::cerr << std::endl; } template <class Head, class... Tail> void debug(Head &&head, Tail &&...tail) { std::cerr << head; if (sizeof...(tail) != 0) { std::cerr << " "; } print(std::forward<Tail>(tail)...); } template <class T> void debug(std::vector<T> &v) { for (auto &a : v) { std::cerr << a; if (&a != &v.back()) { std::cerr << " "; } } std::cerr << std::endl; } template <class T> void debug(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); } } inline bool inside(long long y, long long x, long long H, long long W) { return 0 <= y and y < H and 0 <= x and x < W; } template <class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); } template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); } template <class T> inline std::vector<T> unique(std::vector<T> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } long long sum_of_arithmetic_progression(long long s, long long d, long long n) { return n * (2 * s + (n - 1) * d) / 2; } bool is_power_of_two(long long x) { return !(x & (x - 1)); } long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long gcd(std::vector<long long> &v) { long long ans = v[0]; for (int i = 1; i < (int)v.size(); ++i) { ans = gcd(ans, v[i]); } return ans; } long long lcm(long long a, long long b) { long long g = gcd(a, b); return a / g * b; } const int INF = 1u << 30u; const long long LINF = 1ull << 58u; const double EPS = 1e-9; const long double PI = acos(-1.0); const std::vector<int> dy2 = {0, 1}, dx2 = {1, 0}; const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0}; const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1}, dx8 = {1, 0, -1, 0, 1, 1, -1, -1}; using namespace std; const int MOD = 1000000000 + 7; template <int mod> struct mint { long long x; mint(long long x = 0) : x(x % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) { x -= mod; } return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) { x -= mod; } return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(long long t) const { if (!t) { return 1; } mint a = pow(t >> 1); a *= a; if (t & 1) { a *= *this; } return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; long long modpow(long long base, long long exp, long long mod) { base %= mod; long long result = 1; while (exp > 0) { if (exp & 1) { result = (result * base) % mod; } base = (base * base) % mod; exp >>= 1; } return result; } long long combination(long long n, long long r) { uint64_t ans = 1; for (uint64_t d = 1; d <= r; ++d) { ans *= n--; ans /= d; } return ans; } class Combination { public: int mod; vector<long long> fact; vector<long long> inv; Combination(int n, int mod) : mod(mod) { assert(0 < n); this->fact.resize(n + 1, 1); this->inv.resize(n + 1, 1); for (int i = 1; i < fact.size(); ++i) { this->fact[i] = (i * this->fact[i - 1]) % this->mod; this->inv[i] = modpow(this->fact[i], this->mod - 2, this->mod); } } long long nCr(int n, int k) { assert(0 <= n and n < this->fact.size() and 0 <= k); assert(n >= k); auto a = this->fact[n]; auto b = (this->inv[k] * this->inv[n - k]) % this->mod; return (a * b) % this->mod; } long long nHr(int n, int k) { return nCr(n + k - 1, k); } }; Combination comb(150000, MOD); // 全方位木DP template <typename T> class Rerooting { public: const int num_of_nodes; std::vector<T> ans; private: std::vector<std::vector<int>> tree; std::vector<std::vector<int>> children; // children[u] = [c1, c2, ...] // 問題特有のデータ std::vector<std::unordered_map<int, T>> dp; // dp[u][parent] = // 親がparentであるときのノードuの目的値(uが根のときはparentはnum_of_nodesとなる) vector<int> num_children; public: Rerooting(const int num_of_nodes) : num_of_nodes(num_of_nodes) { this->ans.resize(this->num_of_nodes); this->tree.resize(this->num_of_nodes); this->children.resize(this->num_of_nodes + 1); this->dp.resize(this->num_of_nodes); this->num_children.resize(this->num_of_nodes); } void add_undirected_edge(const int u, const int v) { this->tree[u].emplace_back(v); this->tree[v].emplace_back(u); } void solve() { const int root = 0; // rootを固定したときの,各ノードの値を求める vector<int> num_children(this->num_of_nodes); dfs(root, this->num_of_nodes); // 各ノードをrootとしたときの値を求める dfs2(root, this->num_of_nodes, 1); } // dfs1をすべてのノードに対して行う void debug() { for (int root = 0; root < this->num_of_nodes; ++root) { dfs(root, this->num_of_nodes); this->ans[root] = dp[root][this->num_of_nodes]; } } private: void dfs(const int u, const int parent) { this->children[parent].emplace_back(u); this->num_children[u] = 0; this->dp[u][parent] = 1; for (int i = 0; i < this->tree[u].size(); ++i) { const int v = this->tree[u][i]; if (v == parent) { continue; } this->dfs(v, u); this->num_children[u] += this->num_children[v]; dp[u][parent] *= dp[v][u] * comb.nCr(num_children[u], num_children[v]); } this->num_children[u]++; } void dfs2(const int u, const int parent, mint<MOD> t) { this->ans[u] = dp[u][parent] * t * comb.nCr(this->num_of_nodes - 1, this->num_of_nodes - num_children[u]); for (int v : this->children[u]) { auto t2 = ans[u] / dp[v][u] / comb.nCr(num_of_nodes - 1, this->num_children[v]); dfs2(v, u, t2); } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; Rerooting<mint<MOD>> rr(N); auto tree = make_v<int>(N, 0); FOR(i, 0, N - 1) { int A, B; cin >> A >> B; A--; B--; rr.add_undirected_edge(A, B); } rr.solve(); // rr.debug(); FOR(i, 0, N) { print(rr.ans[i].x); } return 0; }
#include <algorithm> #include <array> #include <assert.h> #include <bitset> #include <climits> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define FOE(i, a) for (auto i : a) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SUM(x) std::accumulate(ALL(x), 0LL) #define MIN(v) *std::min_element(v.begin(), v.end()) #define MAX(v) *std::max_element(v.begin(), v.end()) #define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) #define IS_BIT_ON(bit, i) (bit & (1 << i)) #define BIT_ON(bit, i) (bit |= (1 << i)) #define BIT_OFF(bit, i) (bit &= ~(1 << i)) #define BIT_COUNT(bit) (__builtin_popcount(bit)) typedef long long LL; template <typename T> std::vector<T> make_v(size_t a) { return std::vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } // C++14 template <typename T, typename V> typename std::enable_if<std::is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename std::enable_if<std::is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class T> inline T ceil(T a, T b) { return (a + b - 1) / b; } void print() { std::cout << std::endl; } template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) { std::cout << head; if (sizeof...(tail) != 0) { std::cout << " "; } print(std::forward<Tail>(tail)...); } template <class T> void print(std::vector<T> &v) { for (auto &a : v) { std::cout << a; if (&a != &v.back()) { std::cout << " "; } } std::cout << std::endl; } template <class T> void print(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); } } void debug() { std::cerr << std::endl; } template <class Head, class... Tail> void debug(Head &&head, Tail &&...tail) { std::cerr << head; if (sizeof...(tail) != 0) { std::cerr << " "; } print(std::forward<Tail>(tail)...); } template <class T> void debug(std::vector<T> &v) { for (auto &a : v) { std::cerr << a; if (&a != &v.back()) { std::cerr << " "; } } std::cerr << std::endl; } template <class T> void debug(std::vector<std::vector<T>> &vv) { for (auto &v : vv) { print(v); } } inline bool inside(long long y, long long x, long long H, long long W) { return 0 <= y and y < H and 0 <= x and x < W; } template <class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } template <class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); } template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); } template <class T> inline std::vector<T> unique(std::vector<T> v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); return v; } long long sum_of_arithmetic_progression(long long s, long long d, long long n) { return n * (2 * s + (n - 1) * d) / 2; } bool is_power_of_two(long long x) { return !(x & (x - 1)); } long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long gcd(std::vector<long long> &v) { long long ans = v[0]; for (int i = 1; i < (int)v.size(); ++i) { ans = gcd(ans, v[i]); } return ans; } long long lcm(long long a, long long b) { long long g = gcd(a, b); return a / g * b; } const int INF = 1u << 30u; const long long LINF = 1ull << 58u; const double EPS = 1e-9; const long double PI = acos(-1.0); const std::vector<int> dy2 = {0, 1}, dx2 = {1, 0}; const std::vector<int> dy4 = {0, 1, 0, -1}, dx4 = {1, 0, -1, 0}; const std::vector<int> dy8 = {0, -1, 0, 1, 1, -1, -1, 1}, dx8 = {1, 0, -1, 0, 1, 1, -1, -1}; using namespace std; const int MOD = 1000000000 + 7; template <int mod> struct mint { long long x; mint(long long x = 0) : x(x % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) { x -= mod; } return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) { x -= mod; } return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(long long t) const { if (!t) { return 1; } mint a = pow(t >> 1); a *= a; if (t & 1) { a *= *this; } return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; long long modpow(long long base, long long exp, long long mod) { base %= mod; long long result = 1; while (exp > 0) { if (exp & 1) { result = (result * base) % mod; } base = (base * base) % mod; exp >>= 1; } return result; } long long combination(long long n, long long r) { uint64_t ans = 1; for (uint64_t d = 1; d <= r; ++d) { ans *= n--; ans /= d; } return ans; } class Combination { public: int mod; vector<long long> fact; vector<long long> inv; Combination(int n, int mod) : mod(mod) { assert(0 < n); this->fact.resize(n + 1, 1); this->inv.resize(n + 1, 1); for (int i = 1; i < fact.size(); ++i) { this->fact[i] = (i * this->fact[i - 1]) % this->mod; this->inv[i] = modpow(this->fact[i], this->mod - 2, this->mod); } } long long nCr(int n, int k) { assert(0 <= n and n < this->fact.size() and 0 <= k); assert(n >= k); auto a = this->fact[n]; auto b = (this->inv[k] * this->inv[n - k]) % this->mod; return (a * b) % this->mod; } long long nHr(int n, int k) { return nCr(n + k - 1, k); } }; Combination comb(250000, MOD); // 全方位木DP template <typename T> class Rerooting { public: const int num_of_nodes; std::vector<T> ans; private: std::vector<std::vector<int>> tree; std::vector<std::vector<int>> children; // children[u] = [c1, c2, ...] // 問題特有のデータ std::vector<std::unordered_map<int, T>> dp; // dp[u][parent] = // 親がparentであるときのノードuの目的値(uが根のときはparentはnum_of_nodesとなる) vector<int> num_children; public: Rerooting(const int num_of_nodes) : num_of_nodes(num_of_nodes) { this->ans.resize(this->num_of_nodes); this->tree.resize(this->num_of_nodes); this->children.resize(this->num_of_nodes + 1); this->dp.resize(this->num_of_nodes); this->num_children.resize(this->num_of_nodes); } void add_undirected_edge(const int u, const int v) { this->tree[u].emplace_back(v); this->tree[v].emplace_back(u); } void solve() { const int root = 0; // rootを固定したときの,各ノードの値を求める vector<int> num_children(this->num_of_nodes); dfs(root, this->num_of_nodes); // 各ノードをrootとしたときの値を求める dfs2(root, this->num_of_nodes, 1); } // dfs1をすべてのノードに対して行う void debug() { for (int root = 0; root < this->num_of_nodes; ++root) { dfs(root, this->num_of_nodes); this->ans[root] = dp[root][this->num_of_nodes]; } } private: void dfs(const int u, const int parent) { this->children[parent].emplace_back(u); this->num_children[u] = 0; this->dp[u][parent] = 1; for (int i = 0; i < this->tree[u].size(); ++i) { const int v = this->tree[u][i]; if (v == parent) { continue; } this->dfs(v, u); this->num_children[u] += this->num_children[v]; dp[u][parent] *= dp[v][u] * comb.nCr(num_children[u], num_children[v]); } this->num_children[u]++; } void dfs2(const int u, const int parent, mint<MOD> t) { this->ans[u] = dp[u][parent] * t * comb.nCr(this->num_of_nodes - 1, this->num_of_nodes - num_children[u]); for (int v : this->children[u]) { auto t2 = ans[u] / dp[v][u] / comb.nCr(num_of_nodes - 1, this->num_children[v]); dfs2(v, u, t2); } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; Rerooting<mint<MOD>> rr(N); auto tree = make_v<int>(N, 0); FOR(i, 0, N - 1) { int A, B; cin >> A >> B; A--; B--; rr.add_undirected_edge(A, B); } rr.solve(); // rr.debug(); FOR(i, 0, N) { print(rr.ans[i].x); } return 0; }
replace
284
285
284
285
0
p02728
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key(val): returns the number of values less than val // find_by_order(k): returns an iterator to the kth largest element (0-based) #define pb push_back #define mp make_pair #define ff first #define ss second #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) #define endl "\n" template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) { os << y << " "; } return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[" << p.ff << ", " << p.ss << "]"; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll modexp(ll a, ll b, ll c) { a %= c; ll ans = 1; while (b) { if (b & 1) { ans = (ans * a) % c; } a = (a * a) % c; b >>= 1; } return ans; } ll nxt() { ll x; cin >> x; return x; } const ll L = 2e5 + 5; const ll mod = 1e9 + 7; vector<ll> adj[L]; ll fact[L]; ll invfact[L]; void factorial() { fact[0] = 1; invfact[0] = 1; for (ll i = 1; i < L; i++) { fact[i] = (fact[i - 1] * i) % mod; invfact[i] = modexp(fact[i], mod - 2, mod); } } ll C(ll n, ll r) { ll ans = fact[n]; ans *= invfact[r]; ans %= mod; ans *= invfact[n - r]; ans %= mod; return ans; } ll sz[L]; ll ans[L]; ll res[L]; void dfs(ll src, ll par) { sz[src] = 1; for (auto i : adj[src]) { if (i != par) { dfs(i, src); sz[src] += sz[i]; } } ans[src] = 1; ll rem = sz[src] - 1; for (auto i : adj[src]) { if (i != par) { ans[src] *= ans[i]; ans[src] %= mod; ans[src] *= C(rem, sz[i]); ans[src] %= mod; rem -= sz[i]; } } } void dfs2(ll src, ll par, ll n) { if (par == -1) { res[src] = ans[src]; } else { ll d = C(n - 1, sz[src]) * ans[src]; d %= mod; d = modexp(d, mod - 2, mod); d *= res[par]; d %= mod; res[src] = d; ll rem = n - 1; res[src] *= C(rem, n - sz[src]); res[src] %= mod; rem -= (n - sz[src]); for (auto i : adj[src]) { if (i != par) { res[src] *= ans[i]; res[src] %= mod; res[src] *= C(rem, sz[i]); res[src] %= mod; rem -= sz[i]; } } } for (auto i : adj[src]) { if (i != par) { dfs2(i, src, n); } } } void solve() { ll n = nxt(); factorial(); for (ll i = 0; i < n; i++) { ll a = nxt() - 1, b = nxt() - 1; adj[a].pb(b); adj[b].pb(a); } dfs(0, -1); dfs2(0, -1, n); for (ll i = 0; i < n; i++) { cout << res[i] << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T = 1; // T = nxt(); while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // order_of_key(val): returns the number of values less than val // find_by_order(k): returns an iterator to the kth largest element (0-based) #define pb push_back #define mp make_pair #define ff first #define ss second #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) #define endl "\n" template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x) { os << "{ "; for (auto &y : x) { os << y << " "; } return os << "}"; } template <class X, class Y> ostream &operator<<(ostream &os, pair<X, Y> const &p) { return os << "[" << p.ff << ", " << p.ss << "]"; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll modexp(ll a, ll b, ll c) { a %= c; ll ans = 1; while (b) { if (b & 1) { ans = (ans * a) % c; } a = (a * a) % c; b >>= 1; } return ans; } ll nxt() { ll x; cin >> x; return x; } const ll L = 2e5 + 5; const ll mod = 1e9 + 7; vector<ll> adj[L]; ll fact[L]; ll invfact[L]; void factorial() { fact[0] = 1; invfact[0] = 1; for (ll i = 1; i < L; i++) { fact[i] = (fact[i - 1] * i) % mod; invfact[i] = modexp(fact[i], mod - 2, mod); } } ll C(ll n, ll r) { ll ans = fact[n]; ans *= invfact[r]; ans %= mod; ans *= invfact[n - r]; ans %= mod; return ans; } ll sz[L]; ll ans[L]; ll res[L]; void dfs(ll src, ll par) { sz[src] = 1; for (auto i : adj[src]) { if (i != par) { dfs(i, src); sz[src] += sz[i]; } } ans[src] = 1; ll rem = sz[src] - 1; for (auto i : adj[src]) { if (i != par) { ans[src] *= ans[i]; ans[src] %= mod; ans[src] *= C(rem, sz[i]); ans[src] %= mod; rem -= sz[i]; } } } void dfs2(ll src, ll par, ll n) { if (par == -1) { res[src] = ans[src]; } else { ll d = C(n - 1, sz[src]) * ans[src]; d %= mod; d = modexp(d, mod - 2, mod); d *= res[par]; d %= mod; res[src] = d; ll rem = n - 1; res[src] *= C(rem, n - sz[src]); res[src] %= mod; rem -= (n - sz[src]); for (auto i : adj[src]) { if (i != par) { res[src] *= ans[i]; res[src] %= mod; res[src] *= C(rem, sz[i]); res[src] %= mod; rem -= sz[i]; } } } for (auto i : adj[src]) { if (i != par) { dfs2(i, src, n); } } } void solve() { ll n = nxt(); factorial(); for (ll i = 0; i < n - 1; i++) { ll a = nxt() - 1, b = nxt() - 1; adj[a].pb(b); adj[b].pb(a); } dfs(0, -1); dfs2(0, -1, n); for (ll i = 0; i < n; i++) { cout << res[i] << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T = 1; // T = nxt(); while (T--) { solve(); } return 0; }
replace
181
182
181
182
-11
p02728
C++
Time Limit Exceeded
#pragma GCC optimize("Ofast") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long int; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using psi = pair<string, int>; using pis = pair<int, string>; using psl = pair<string, ll>; using pls = pair<ll, string>; using pss = pair<string, string>; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vector<T>>; template <typename T> using vvvc = vector<vector<vector<T>>>; template <typename T> using vvvvc = vector<vvvc<T>>; template <typename T> using vvvvvc = vector<vvvvc<T>>; template <class T, class U> inline constexpr bool chmin(T &a, const U b) { if (a <= b) return false; a = b; return true; } template <class T, class U> inline constexpr bool chmax(T &a, const U b) { if (a >= b) return false; a = b; return true; } #define bit(n, k) ((n >> k) & 1) inline void bin101() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } template <typename T> inline void Yes(T flag) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } template <typename T> inline void YES(T flag) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } // 1-indexed vector cin template <typename T> inline void vin1(vector<T> &v) { for (int i = 1; i < v.size(); i++) cin >> v[i]; } // 0-indexed vector cin template <typename T> inline void vin0(vector<T> &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } // 1-indexed vector<vector> cin template <typename T> inline void vin1(vector<vector<T>> &v) { for (int i = 1; i < v.size(); i++) { for (int j = 1; j < v[i].size(); j++) cin >> v[i][j]; } } // 0-indexed vector<vector> cin template <typename T> inline void vin0(vector<vector<T>> &v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) cin >> v[i][j]; } } // デバッグ template <typename T> inline void vout(const vector<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { cout << i << " " << v[i] << '\n'; } cout << "end\n" << endl; } // デバッグ template <typename T> inline void vout(const vvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { cout << i << " " << j << " " << v[i][j] << '\n'; } } cout << "\nend\n" << endl; } // デバッグ(グリッド) template <typename T> inline void gvout(const vector<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { if (i) cout << " "; cout << v[i]; } cout << "\nend\n" << endl; } // デバッグ(グリッド) template <typename T> inline void gvout(const vvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { if (j) cout << " "; cout << v[i][j]; } cout << endl; } cout << "end\n" << endl; } // デバッグ template <typename T> inline void vout(const vvvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { int sssz = v[i][j].size(); for (int k = 0; k < sssz; k++) { cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n'; } } } cout << "end\n" << endl; } // pair cout template <typename T, typename U> inline ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } // pair cin template <typename T, typename U> inline istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } // ソート template <typename T> inline void vsort(vector<T> &v) { sort(v.begin(), v.end()); } // 逆順ソート template <typename T> inline void rvsort(vector<T> &v) { sort(v.rbegin(), v.rend()); } // 要素数a 初期値x template <typename T> inline vector<T> vmake(int a, T x) { return vector<T>(a, x); } // data[a][b] 初期値x template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) { return vector<vector<T>>(a, vector<T>(b, x)); } // data[a][b][c] 初期値x template <typename T> inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) { return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x))); } // data[a][b][c][d] 初期値x template <typename T> inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d, T x) { return vector<vector<vector<vector<T>>>>(a, vvvc<T>(b, vvc<T>(c, vc<T>(d, x)))); } // data[a][b][c][d][e] 初期値x template <typename T> inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) { return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x))))); } // 1ビットの数を返す inline int popcount(int x) { return __builtin_popcount(x); } // 1ビットの数を返す inline int popcount(ll x) { return __builtin_popcountll(x); } // queのfront() pop() template <typename T> inline T pop(queue<T> &que) { T x = que.front(); que.pop(); return x; } // priority_que top() pop() template <typename T> inline T pop(priority_queue<T> &que) { T x = que.top(); que.pop(); return x; } // stack top() pop() template <typename T> inline T pop(stack<T> &st) { T x = st.top(); st.pop(); return x; } #define SZ(x) ((int)x.size()) #define pb push_back /* 満たすものの個数を返す mode:0 x未満 mode:1 x以下の数 mode:2 x以上の数 mode:3 x超 mode:4 x */ template <typename T> inline int count_bound(vector<T> &v, T x, int mode) { switch (mode) { case 0: return lower_bound(v.begin(), v.end(), x) - v.begin(); case 1: return upper_bound(v.begin(), v.end(), x) - v.begin(); case 2: return v.end() - lower_bound(v.begin(), v.end(), x); case 3: return v.end() - upper_bound(v.begin(), v.end(), x); case 4: return upper_bound(v.begin(), v.end(), x) - lower_bound(v.begin(), v.end(), x); } } /* mode:0 xより小さい数で最大の数 mode:1 x以下の数で最大の数 mode:2 x以上の数で最小の数 mode:3 xより大きい数で最小の数 */ template <typename T> inline T value_bound(vector<T> &v, T x, int mode) { switch (mode) { case 0: return *(--lower_bound(v.begin(), v.end(), x)); case 1: return *(--upper_bound(v.begin(), v.end(), x)); case 2: return *lower_bound(v.begin(), v.end(), x); case 3: return *upper_bound(v.begin(), v.end(), x); } } constexpr int MAX = 1 << 30; constexpr ll INF = 1LL << 62; constexpr ll MOD = 1e9 + 7; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ struct ModInt { using u64 = uint_fast64_t; u64 a; constexpr ModInt() : a(0) {} constexpr ModInt(ll x) : a((x >= 0) ? (x % MOD) : (x % MOD + MOD)) {} inline constexpr ModInt operator+(const ModInt rhs) const noexcept { return ModInt(*this) += rhs; } inline constexpr ModInt operator-(const ModInt rhs) const noexcept { return ModInt(*this) -= rhs; } inline constexpr ModInt operator*(const ModInt rhs) const noexcept { return ModInt(*this) *= rhs; } inline constexpr ModInt operator/(const ModInt rhs) const noexcept { return ModInt(*this) /= rhs; } inline constexpr ModInt operator+(const ll rhs) const noexcept { return ModInt(*this) += rhs; } inline constexpr ModInt operator-(const ll rhs) const noexcept { return ModInt(*this) -= rhs; } inline constexpr ModInt operator*(const ll rhs) const noexcept { return ModInt(*this) *= rhs; } inline constexpr ModInt operator/(const ll rhs) const noexcept { return ModInt(*this) /= rhs; } inline constexpr ModInt &operator+=(const ModInt rhs) noexcept { a += rhs.a; if (a >= MOD) a -= MOD; return *this; } inline constexpr ModInt &operator-=(const ModInt rhs) noexcept { if (rhs.a > a) a += MOD; a -= rhs.a; return *this; } inline constexpr ModInt &operator*=(const ModInt rhs) noexcept { a = (a * rhs.a) % MOD; return *this; } inline constexpr ModInt &operator/=(ModInt rhs) noexcept { a = (a * rhs.inverse().a) % MOD; return *this; } inline constexpr ModInt &operator+=(const ll rhs) noexcept { a += rhs; if (a >= MOD) a -= MOD; return *this; } inline constexpr ModInt &operator-=(const ll rhs) noexcept { if (rhs > a) a += MOD; a -= rhs; return *this; } inline constexpr ModInt &operator*=(const ll rhs) noexcept { a = (a * rhs) % MOD; return *this; } inline constexpr ModInt &operator/=(ll rhs) noexcept { a = (a * ModInt(rhs).inverse().a) % MOD; return *this; } inline constexpr ModInt operator=(ll x) noexcept { x %= MOD; if (x < 0) x += MOD; a = x; return *this; } inline constexpr bool operator==(const ModInt p) const noexcept { return a == p.a; } inline constexpr bool operator!=(const ModInt p) const noexcept { return a != p.a; } inline constexpr ModInt pow(ll N) const noexcept { ModInt ans(1LL), p(a); while (N > 0) { if (bit(N, 0)) { ans *= p; } p *= p; N >>= 1; } return ans; } inline constexpr ModInt inverse() const noexcept { return pow(MOD - 2); } }; inline constexpr ModInt operator+(const ll &a, const ModInt &b) noexcept { return ModInt(a) += b; } inline constexpr ModInt operator-(const ll &a, const ModInt &b) noexcept { return ModInt(a) -= b; } inline constexpr ModInt operator*(const ll &a, const ModInt &b) noexcept { return ModInt(a) *= b; } inline constexpr ModInt operator/(const ll &a, const ModInt &b) noexcept { return ModInt(a) /= b; } // cout inline ostream &operator<<(ostream &os, const ModInt &p) { return os << p.a; } // cin inline istream &operator>>(istream &is, ModInt &p) { ll t; is >> t; p = t; return is; } inline constexpr ModInt Mr(ll p) { p %= MOD; if (p < 0) p += MOD; return ModInt(p); } struct Binominal { vector<ModInt> fac, finv, inv; // fac[n]:n! finv:(n!)の逆元 int sz; Binominal(int n = 10) : sz(0) { if (n == 0) n = 10; init(n); } inline void init(int n) { fac.resize(n + 1, 1); finv.resize(n + 1, 1); inv.resize(n + 1, 1); for (int i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } sz = n; } // nCk(n,k<=N) をO(1)で求める inline ModInt com(int n, int k) { if (n < k) return ModInt(0); if (n < 0 || k < 0) return ModInt(0); if (n > sz) init(n); return fac[n] * finv[k] * finv[n - k]; } // nCk(k<=N) をO(k) で求める inline ModInt rcom(ll n, int k) { if (n < 0 || k < 0 || n < k) return ModInt(0); if (k > sz) init(k); ModInt ret(1); for (int i = 0; i < k; i++) { ret *= (n - i); } ret *= finv[k]; return ret; } // 重複組み合わせ n種類のものから重複を許してk個を選ぶ // 〇がn個,|がk個 inline ModInt h(int n, int k) { return com(n + k - 1, k); } }; Binominal B; // Tはdp(頂点)の型 Dataは辺のコスト template <typename T, typename Data> struct ReRooting { struct Node { int to, rev; Data data; Node(int to, int rev, Data data) : to(to), rev(rev), data(data) {} }; using F1 = function<T(T, T)>; // 頂点と頂点 using F2 = function<T(T, Data)>; // 頂点と辺 vector<vector<Node>> g; vector<vector<T>> ldp, rdp; vector<int> lptr, rptr; const F1 f1; const F2 f2; const T ident; // Tの単位元 ex.最小値を求める場合はinf ReRooting(int n, const F1 &f1, const F2 &f2, const T &ident) : g(n), ldp(n), rdp(n), lptr(n), rptr(n), f1(f1), f2(f2), ident(ident) {} void add_edge(int u, int v, const Data &d) { g[u].emplace_back(v, g[v].size(), d); g[v].emplace_back(u, (int)g[u].size() - 1, d); } // 注意が必要 u->vを実際に使うときはeの値を使う void add_edge(int u, int v, const Data &d, const Data &e) { g[u].emplace_back(v, g[v].size(), d); g[v].emplace_back(u, (int)g[u].size() - 1, e); } T dfs(int idx, int par) { while (lptr[idx] != par && lptr[idx] < g[idx].size()) { auto &e = g[idx][lptr[idx]]; ldp[idx][lptr[idx] + 1] = f1(ldp[idx][lptr[idx]], f2(dfs(e.to, e.rev), e.data)); lptr[idx]++; } while (rptr[idx] != par && rptr[idx] >= 0) { auto &e = g[idx][rptr[idx]]; rdp[idx][rptr[idx]] = f1(rdp[idx][rptr[idx] + 1], f2(dfs(e.to, e.rev), e.data)); rptr[idx]--; } if (par < 0) return rdp[idx][0]; return f1(ldp[idx][par], rdp[idx][par + 1]); } vector<T> solve() { for (int i = 0; i < g.size(); i++) { // cout<<i<<endl; ldp[i].assign(g[i].size() + 1, ident); rdp[i].assign(g[i].size() + 1, ident); lptr[i] = 0; rptr[i] = (int)g[i].size() - 1; } vector<T> ret; // cout<<000<<endl; for (int i = 0; i < g.size(); i++) { // cout<<i<<endl; ret.push_back(dfs(i, -1)); } return ret; } }; signed main() { bin101(); int N; cin >> N; using tm = tuple<int, ModInt>; auto f1 = [](tm a, tm b) { return tm(get<0>(a) + get<0>(b), get<1>(a) * get<1>(b) * B.com(get<0>(a) + get<0>(b), get<0>(a))); }; auto f2 = [](tm a, int b) { get<0>(a)++; return a; }; ReRooting<tm, int> root(N, f1, f2, tm(0, Mr(1))); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; root.add_edge(a, b, 0); } auto ret = root.solve(); // cout<<1<<endl; for (int i = 0; i < ret.size(); i++) { int aa; ModInt ab; tie(aa, ab) = ret[i]; cout << ab << "\n"; } }
#pragma GCC optimize("Ofast") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long int; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using psi = pair<string, int>; using pis = pair<int, string>; using psl = pair<string, ll>; using pls = pair<ll, string>; using pss = pair<string, string>; template <typename T> using vc = vector<T>; template <typename T> using vvc = vector<vector<T>>; template <typename T> using vvvc = vector<vector<vector<T>>>; template <typename T> using vvvvc = vector<vvvc<T>>; template <typename T> using vvvvvc = vector<vvvvc<T>>; template <class T, class U> inline constexpr bool chmin(T &a, const U b) { if (a <= b) return false; a = b; return true; } template <class T, class U> inline constexpr bool chmax(T &a, const U b) { if (a >= b) return false; a = b; return true; } #define bit(n, k) ((n >> k) & 1) inline void bin101() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } template <typename T> inline void Yes(T flag) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } template <typename T> inline void YES(T flag) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } // 1-indexed vector cin template <typename T> inline void vin1(vector<T> &v) { for (int i = 1; i < v.size(); i++) cin >> v[i]; } // 0-indexed vector cin template <typename T> inline void vin0(vector<T> &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } // 1-indexed vector<vector> cin template <typename T> inline void vin1(vector<vector<T>> &v) { for (int i = 1; i < v.size(); i++) { for (int j = 1; j < v[i].size(); j++) cin >> v[i][j]; } } // 0-indexed vector<vector> cin template <typename T> inline void vin0(vector<vector<T>> &v) { for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].size(); j++) cin >> v[i][j]; } } // デバッグ template <typename T> inline void vout(const vector<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { cout << i << " " << v[i] << '\n'; } cout << "end\n" << endl; } // デバッグ template <typename T> inline void vout(const vvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { cout << i << " " << j << " " << v[i][j] << '\n'; } } cout << "\nend\n" << endl; } // デバッグ(グリッド) template <typename T> inline void gvout(const vector<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { if (i) cout << " "; cout << v[i]; } cout << "\nend\n" << endl; } // デバッグ(グリッド) template <typename T> inline void gvout(const vvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { if (j) cout << " "; cout << v[i][j]; } cout << endl; } cout << "end\n" << endl; } // デバッグ template <typename T> inline void vout(const vvvc<T> &v) { cout << "\nstart\n"; const int sz = v.size(); for (int i = 0; i < sz; i++) { int ssz = v[i].size(); for (int j = 0; j < ssz; j++) { int sssz = v[i][j].size(); for (int k = 0; k < sssz; k++) { cout << i << " " << j << " " << k << " " << v[i][j][k] << '\n'; } } } cout << "end\n" << endl; } // pair cout template <typename T, typename U> inline ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } // pair cin template <typename T, typename U> inline istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } // ソート template <typename T> inline void vsort(vector<T> &v) { sort(v.begin(), v.end()); } // 逆順ソート template <typename T> inline void rvsort(vector<T> &v) { sort(v.rbegin(), v.rend()); } // 要素数a 初期値x template <typename T> inline vector<T> vmake(int a, T x) { return vector<T>(a, x); } // data[a][b] 初期値x template <typename T> inline vector<vector<T>> vmake(int a, int b, T x) { return vector<vector<T>>(a, vector<T>(b, x)); } // data[a][b][c] 初期値x template <typename T> inline vector<vector<vector<T>>> vmake(int a, int b, int c, T x) { return vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, x))); } // data[a][b][c][d] 初期値x template <typename T> inline vector<vector<vector<vector<T>>>> vmake(int a, int b, int c, int d, T x) { return vector<vector<vector<vector<T>>>>(a, vvvc<T>(b, vvc<T>(c, vc<T>(d, x)))); } // data[a][b][c][d][e] 初期値x template <typename T> inline vvvvvc<T> vmake(int a, int b, int c, int d, int e, T x) { return vvvvvc<T>(a, vvvvc<T>(b, vvvc<T>(c, vvc<T>(d, vc<T>(e, x))))); } // 1ビットの数を返す inline int popcount(int x) { return __builtin_popcount(x); } // 1ビットの数を返す inline int popcount(ll x) { return __builtin_popcountll(x); } // queのfront() pop() template <typename T> inline T pop(queue<T> &que) { T x = que.front(); que.pop(); return x; } // priority_que top() pop() template <typename T> inline T pop(priority_queue<T> &que) { T x = que.top(); que.pop(); return x; } // stack top() pop() template <typename T> inline T pop(stack<T> &st) { T x = st.top(); st.pop(); return x; } #define SZ(x) ((int)x.size()) #define pb push_back /* 満たすものの個数を返す mode:0 x未満 mode:1 x以下の数 mode:2 x以上の数 mode:3 x超 mode:4 x */ template <typename T> inline int count_bound(vector<T> &v, T x, int mode) { switch (mode) { case 0: return lower_bound(v.begin(), v.end(), x) - v.begin(); case 1: return upper_bound(v.begin(), v.end(), x) - v.begin(); case 2: return v.end() - lower_bound(v.begin(), v.end(), x); case 3: return v.end() - upper_bound(v.begin(), v.end(), x); case 4: return upper_bound(v.begin(), v.end(), x) - lower_bound(v.begin(), v.end(), x); } } /* mode:0 xより小さい数で最大の数 mode:1 x以下の数で最大の数 mode:2 x以上の数で最小の数 mode:3 xより大きい数で最小の数 */ template <typename T> inline T value_bound(vector<T> &v, T x, int mode) { switch (mode) { case 0: return *(--lower_bound(v.begin(), v.end(), x)); case 1: return *(--upper_bound(v.begin(), v.end(), x)); case 2: return *lower_bound(v.begin(), v.end(), x); case 3: return *upper_bound(v.begin(), v.end(), x); } } constexpr int MAX = 1 << 30; constexpr ll INF = 1LL << 62; constexpr ll MOD = 1e9 + 7; int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, -1, 1}; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ struct ModInt { using u64 = uint_fast64_t; u64 a; constexpr ModInt() : a(0) {} constexpr ModInt(ll x) : a((x >= 0) ? (x % MOD) : (x % MOD + MOD)) {} inline constexpr ModInt operator+(const ModInt rhs) const noexcept { return ModInt(*this) += rhs; } inline constexpr ModInt operator-(const ModInt rhs) const noexcept { return ModInt(*this) -= rhs; } inline constexpr ModInt operator*(const ModInt rhs) const noexcept { return ModInt(*this) *= rhs; } inline constexpr ModInt operator/(const ModInt rhs) const noexcept { return ModInt(*this) /= rhs; } inline constexpr ModInt operator+(const ll rhs) const noexcept { return ModInt(*this) += rhs; } inline constexpr ModInt operator-(const ll rhs) const noexcept { return ModInt(*this) -= rhs; } inline constexpr ModInt operator*(const ll rhs) const noexcept { return ModInt(*this) *= rhs; } inline constexpr ModInt operator/(const ll rhs) const noexcept { return ModInt(*this) /= rhs; } inline constexpr ModInt &operator+=(const ModInt rhs) noexcept { a += rhs.a; if (a >= MOD) a -= MOD; return *this; } inline constexpr ModInt &operator-=(const ModInt rhs) noexcept { if (rhs.a > a) a += MOD; a -= rhs.a; return *this; } inline constexpr ModInt &operator*=(const ModInt rhs) noexcept { a = (a * rhs.a) % MOD; return *this; } inline constexpr ModInt &operator/=(ModInt rhs) noexcept { a = (a * rhs.inverse().a) % MOD; return *this; } inline constexpr ModInt &operator+=(const ll rhs) noexcept { a += rhs; if (a >= MOD) a -= MOD; return *this; } inline constexpr ModInt &operator-=(const ll rhs) noexcept { if (rhs > a) a += MOD; a -= rhs; return *this; } inline constexpr ModInt &operator*=(const ll rhs) noexcept { a = (a * rhs) % MOD; return *this; } inline constexpr ModInt &operator/=(ll rhs) noexcept { a = (a * ModInt(rhs).inverse().a) % MOD; return *this; } inline constexpr ModInt operator=(ll x) noexcept { x %= MOD; if (x < 0) x += MOD; a = x; return *this; } inline constexpr bool operator==(const ModInt p) const noexcept { return a == p.a; } inline constexpr bool operator!=(const ModInt p) const noexcept { return a != p.a; } inline constexpr ModInt pow(ll N) const noexcept { ModInt ans(1LL), p(a); while (N > 0) { if (bit(N, 0)) { ans *= p; } p *= p; N >>= 1; } return ans; } inline constexpr ModInt inverse() const noexcept { return pow(MOD - 2); } }; inline constexpr ModInt operator+(const ll &a, const ModInt &b) noexcept { return ModInt(a) += b; } inline constexpr ModInt operator-(const ll &a, const ModInt &b) noexcept { return ModInt(a) -= b; } inline constexpr ModInt operator*(const ll &a, const ModInt &b) noexcept { return ModInt(a) *= b; } inline constexpr ModInt operator/(const ll &a, const ModInt &b) noexcept { return ModInt(a) /= b; } // cout inline ostream &operator<<(ostream &os, const ModInt &p) { return os << p.a; } // cin inline istream &operator>>(istream &is, ModInt &p) { ll t; is >> t; p = t; return is; } inline constexpr ModInt Mr(ll p) { p %= MOD; if (p < 0) p += MOD; return ModInt(p); } struct Binominal { vector<ModInt> fac, finv, inv; // fac[n]:n! finv:(n!)の逆元 int sz; Binominal(int n = 10) : sz(0) { if (n == 0) n = 10; init(n); } inline void init(int n) { fac.resize(n + 1, 1); finv.resize(n + 1, 1); inv.resize(n + 1, 1); for (int i = 2; i <= n; i++) { fac[i] = fac[i - 1] * i; inv[i] = MOD - inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } sz = n; } // nCk(n,k<=N) をO(1)で求める inline ModInt com(int n, int k) { if (n < k) return ModInt(0); if (n < 0 || k < 0) return ModInt(0); if (n > sz) init(n); return fac[n] * finv[k] * finv[n - k]; } // nCk(k<=N) をO(k) で求める inline ModInt rcom(ll n, int k) { if (n < 0 || k < 0 || n < k) return ModInt(0); if (k > sz) init(k); ModInt ret(1); for (int i = 0; i < k; i++) { ret *= (n - i); } ret *= finv[k]; return ret; } // 重複組み合わせ n種類のものから重複を許してk個を選ぶ // 〇がn個,|がk個 inline ModInt h(int n, int k) { return com(n + k - 1, k); } }; Binominal B; // Tはdp(頂点)の型 Dataは辺のコスト template <typename T, typename Data> struct ReRooting { struct Node { int to, rev; Data data; Node(int to, int rev, Data data) : to(to), rev(rev), data(data) {} }; using F1 = function<T(T, T)>; // 頂点と頂点 using F2 = function<T(T, Data)>; // 頂点と辺 vector<vector<Node>> g; vector<vector<T>> ldp, rdp; vector<int> lptr, rptr; const F1 f1; const F2 f2; const T ident; // Tの単位元 ex.最小値を求める場合はinf ReRooting(int n, const F1 &f1, const F2 &f2, const T &ident) : g(n), ldp(n), rdp(n), lptr(n), rptr(n), f1(f1), f2(f2), ident(ident) {} void add_edge(int u, int v, const Data &d) { g[u].emplace_back(v, g[v].size(), d); g[v].emplace_back(u, (int)g[u].size() - 1, d); } // 注意が必要 u->vを実際に使うときはeの値を使う void add_edge(int u, int v, const Data &d, const Data &e) { g[u].emplace_back(v, g[v].size(), d); g[v].emplace_back(u, (int)g[u].size() - 1, e); } T dfs(int idx, int par) { while (lptr[idx] != par && lptr[idx] < g[idx].size()) { auto &e = g[idx][lptr[idx]]; ldp[idx][lptr[idx] + 1] = f1(ldp[idx][lptr[idx]], f2(dfs(e.to, e.rev), e.data)); lptr[idx]++; } while (rptr[idx] != par && rptr[idx] >= 0) { auto &e = g[idx][rptr[idx]]; rdp[idx][rptr[idx]] = f1(rdp[idx][rptr[idx] + 1], f2(dfs(e.to, e.rev), e.data)); rptr[idx]--; } if (par < 0) return rdp[idx][0]; return f1(ldp[idx][par], rdp[idx][par + 1]); } vector<T> solve() { for (int i = 0; i < g.size(); i++) { // cout<<i<<endl; ldp[i].assign(g[i].size() + 1, ident); rdp[i].assign(g[i].size() + 1, ident); lptr[i] = 0; rptr[i] = (int)g[i].size() - 1; } vector<T> ret; // cout<<000<<endl; for (int i = 0; i < g.size(); i++) { // cout<<i<<endl; ret.push_back(dfs(i, -1)); } return ret; } }; signed main() { bin101(); int N; cin >> N; using tm = tuple<int, ModInt>; B.init(210000); auto f1 = [](tm a, tm b) { return tm(get<0>(a) + get<0>(b), get<1>(a) * get<1>(b) * B.com(get<0>(a) + get<0>(b), get<0>(a))); }; auto f2 = [](tm a, int b) { get<0>(a)++; return a; }; ReRooting<tm, int> root(N, f1, f2, tm(0, Mr(1))); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; root.add_edge(a, b, 0); } auto ret = root.solve(); // cout<<1<<endl; for (int i = 0; i < ret.size(); i++) { int aa; ModInt ab; tie(aa, ab) = ret[i]; cout << ab << "\n"; } }
replace
554
555
554
555
TLE
p02728
C++
Runtime Error
// #include <fstream> #include <cstring> #include <iostream> #include <vector> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define MOD 1000000007 #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, b) FOR(i, 0, b) #define RFO(i, a, b) for (int i = (b - 1); i >= a; i--) #define RF0(i, b) RFO(i, 0, b) #define lli long long int #define pii pair<int, int> #define add(a, b) ((int)(((lli)a + b) % MOD)) #define mul(a, b) ((int)(((lli)a * b) % MOD)) // ifstream cin ("cinput.in"); // ofstream cout ("coutput.out"); int N, a, b; vector<int> graph[200000]; int fct[200000][2]; int dp[200000]; int nbel[200000]; int mod_exp(int x, int y) { int res = 1; x = x % MOD; while (y > 0) { if (y & 1) res = mul(res, x); y = y >> 1; x = mul(x, x); } return res; } int bc(int n, int k) { return mul(mul(fct[n][0], fct[k][1]), fct[n - k][1]); } int dfs(int node, int par) { // returns # below vector<int> ks; dp[node] = 1; nbel[node] = 0; for (int ne : graph[node]) { if (ne == par) continue; int res = dfs(ne, node); nbel[node] += res; ks.emplace_back(res); } int nbl2 = nbel[node]; for (int ne : graph[node]) { if (ne == par) continue; int k = *(--ks.end()); ks.pop_back(); dp[node] = mul(mul(dp[ne], bc(nbl2, k)), dp[node]); nbl2 -= k; } return nbel[node] + 1; } void dfs2(int node, int par) { if (par != -1) { // dp[par]/bc(N-1, nbel[node]+1)*bc(N,N-nbel[node]-1) dp[node] = mul(dp[par], mul(mod_exp(bc(N - 1, nbel[node] + 1), MOD - 2), bc(N - 1, N - nbel[node] - 1))); } for (int ne : graph[node]) { if (ne == par) continue; dfs2(ne, node); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fct[0][0] = 1; fct[0][1] = mod_exp(1, MOD - 2); FOR(i, 1, 200001) { fct[i][0] = mul(fct[i - 1][0], i); fct[i][1] = mod_exp(fct[i][0], MOD - 2); } cin >> N; F0R(i, N - 1) { cin >> a >> b; graph[a - 1].emplace_back(b - 1); graph[b - 1].emplace_back(a - 1); } dfs(0, -1); dfs2(0, -1); F0R(i, N) cout << dp[i] << '\n'; }
// #include <fstream> #include <cstring> #include <iostream> #include <vector> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define MOD 1000000007 #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define F0R(i, b) FOR(i, 0, b) #define RFO(i, a, b) for (int i = (b - 1); i >= a; i--) #define RF0(i, b) RFO(i, 0, b) #define lli long long int #define pii pair<int, int> #define add(a, b) ((int)(((lli)a + b) % MOD)) #define mul(a, b) ((int)(((lli)a * b) % MOD)) // ifstream cin ("cinput.in"); // ofstream cout ("coutput.out"); int N, a, b; vector<int> graph[200000]; int fct[200001][2]; int dp[200000]; int nbel[200000]; int mod_exp(int x, int y) { int res = 1; x = x % MOD; while (y > 0) { if (y & 1) res = mul(res, x); y = y >> 1; x = mul(x, x); } return res; } int bc(int n, int k) { return mul(mul(fct[n][0], fct[k][1]), fct[n - k][1]); } int dfs(int node, int par) { // returns # below vector<int> ks; dp[node] = 1; nbel[node] = 0; for (int ne : graph[node]) { if (ne == par) continue; int res = dfs(ne, node); nbel[node] += res; ks.emplace_back(res); } int nbl2 = nbel[node]; for (int ne : graph[node]) { if (ne == par) continue; int k = *(--ks.end()); ks.pop_back(); dp[node] = mul(mul(dp[ne], bc(nbl2, k)), dp[node]); nbl2 -= k; } return nbel[node] + 1; } void dfs2(int node, int par) { if (par != -1) { // dp[par]/bc(N-1, nbel[node]+1)*bc(N,N-nbel[node]-1) dp[node] = mul(dp[par], mul(mod_exp(bc(N - 1, nbel[node] + 1), MOD - 2), bc(N - 1, N - nbel[node] - 1))); } for (int ne : graph[node]) { if (ne == par) continue; dfs2(ne, node); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); fct[0][0] = 1; fct[0][1] = mod_exp(1, MOD - 2); FOR(i, 1, 200001) { fct[i][0] = mul(fct[i - 1][0], i); fct[i][1] = mod_exp(fct[i][0], MOD - 2); } cin >> N; F0R(i, N - 1) { cin >> a >> b; graph[a - 1].emplace_back(b - 1); graph[b - 1].emplace_back(a - 1); } dfs(0, -1); dfs2(0, -1); F0R(i, N) cout << dp[i] << '\n'; }
replace
24
25
24
25
0
p02728
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 2e5 + 54; const long long MOD = 1000000007; struct point { int from, to; } eg[200010]; int front[N], num; void lian(int x, int b) { eg[++num].to = b; eg[num].from = front[x]; front[x] = num; } long long ksm(long long x, long long b) { long long maretu = 1; for (; b; b >>= 1) { if (b & 1) { maretu = maretu * x % MOD; } x = x * x % MOD; } return maretu; } int n, vis[N]; long long jc[N], ny[N], ru[N], ans[N], siz[N], gl[N]; long long dfs(int o, int fa) { gl[o] = 1; siz[o] = 1; for (int i = front[o]; i; i = eg[i].from) { int to = eg[i].to; if (to == fa) continue; gl[o] *= dfs(to, o); gl[o] %= MOD; siz[o] += siz[to]; } // printf("%d %lld\n", o, (gl * ny[siz[o]]) % MOD); return (gl[o] * ny[siz[o]]) % MOD; } void check(int o) { // printf("%d\n", o); vis[o] = 1; ans[o] = (((jc[n] * gl[o]) % MOD) * ny[n] % MOD) % MOD; // printf("%lld\n", ans); for (int i = front[o]; i; i = eg[i].from) { int to = eg[i].to; if (vis[to] == 1) continue; long long ori_gl1, ori_gl2, ori_siz1, ori_siz2; ori_gl1 = gl[o]; ori_gl2 = gl[to]; ori_siz1 = siz[o]; ori_siz2 = siz[to]; gl[o] = (gl[o] * ksm((gl[to] * ny[siz[to]]) % MOD, MOD - 2)) % MOD; siz[o] = n - siz[to]; gl[to] = gl[to] * ((gl[o] * ny[siz[o]]) % MOD) % MOD; siz[to] = n; check(to); gl[o] = ori_gl1; gl[to] = ori_gl2; siz[o] = ori_siz1; siz[to] = ori_siz2; } } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, b; scanf("%d%d", &x, &b); ++ru[x]; ++ru[b]; lian(x, b); lian(b, x); } jc[0] = ny[0] = 1; for (long long i = 1; i <= n; i++) { jc[i] = jc[i - 1] * i % MOD; ny[i] = ksm(i, MOD - 2); } dfs(1, 0); check(1); for (int i = 1; i <= n; ++i) std::cout << ans[i] << '\n'; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 2e5 + 54; const long long MOD = 1000000007; struct point { int from, to; } eg[N << 1]; int front[N], num; void lian(int x, int b) { eg[++num].to = b; eg[num].from = front[x]; front[x] = num; } long long ksm(long long x, long long b) { long long maretu = 1; for (; b; b >>= 1) { if (b & 1) { maretu = maretu * x % MOD; } x = x * x % MOD; } return maretu; } int n, vis[N]; long long jc[N], ny[N], ru[N], ans[N], siz[N], gl[N]; long long dfs(int o, int fa) { gl[o] = 1; siz[o] = 1; for (int i = front[o]; i; i = eg[i].from) { int to = eg[i].to; if (to == fa) continue; gl[o] *= dfs(to, o); gl[o] %= MOD; siz[o] += siz[to]; } // printf("%d %lld\n", o, (gl * ny[siz[o]]) % MOD); return (gl[o] * ny[siz[o]]) % MOD; } void check(int o) { // printf("%d\n", o); vis[o] = 1; ans[o] = (((jc[n] * gl[o]) % MOD) * ny[n] % MOD) % MOD; // printf("%lld\n", ans); for (int i = front[o]; i; i = eg[i].from) { int to = eg[i].to; if (vis[to] == 1) continue; long long ori_gl1, ori_gl2, ori_siz1, ori_siz2; ori_gl1 = gl[o]; ori_gl2 = gl[to]; ori_siz1 = siz[o]; ori_siz2 = siz[to]; gl[o] = (gl[o] * ksm((gl[to] * ny[siz[to]]) % MOD, MOD - 2)) % MOD; siz[o] = n - siz[to]; gl[to] = gl[to] * ((gl[o] * ny[siz[o]]) % MOD) % MOD; siz[to] = n; check(to); gl[o] = ori_gl1; gl[to] = ori_gl2; siz[o] = ori_siz1; siz[to] = ori_siz2; } } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, b; scanf("%d%d", &x, &b); ++ru[x]; ++ru[b]; lian(x, b); lian(b, x); } jc[0] = ny[0] = 1; for (long long i = 1; i <= n; i++) { jc[i] = jc[i - 1] * i % MOD; ny[i] = ksm(i, MOD - 2); } dfs(1, 0); check(1); for (int i = 1; i <= n; ++i) std::cout << ans[i] << '\n'; }
replace
8
9
8
9
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(n) begin(n), end(n) ll factorial(ll x) { if (x == 1 || x == 0) { return 1; } else { return x * factorial(x - 1); } } ll combination(ll n, ll r) { return factorial(n) / (factorial(r) * factorial(n - r)); } int main() { ll n, m; cin >> n >> m; int odd = 0, even = 0; if (n <= 1) even = 0; else even = combination(n, 2); if (m <= 1) odd = 0; else odd = combination(m, 2); int ans = even + odd; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(n) begin(n), end(n) ll factorial(ll x) { if (x == 1 || x == 0) { return 1; } else { return x * factorial(x - 1); } } ll combination(ll n, ll r) { ll tmp = 1; REP(i, r) { tmp *= n--; tmp /= i + 1; } return tmp; } int main() { ll n, m; cin >> n >> m; int odd = 0, even = 0; if (n <= 1) even = 0; else even = combination(n, 2); if (m <= 1) odd = 0; else odd = combination(m, 2); int ans = even + odd; cout << ans << endl; }
replace
15
16
15
21
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int64_t x = 1; int64_t y = 1; for (int i = 1; i < N + 1; i++) { x *= i; } for (int i = 1; i < N - 1; i++) { y *= i; } int z = x / (2 * y); int64_t a = 1; int64_t b = 1; for (int i = 1; i < M + 1; i++) { a *= i; } for (int i = 1; i < M - 1; i++) { b *= i; } int c = a / (2 * b); cout << z + c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl; }
replace
6
29
6
7
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 1e5 + 7; ll fact(ll x) { ll sum = 1; for (int i = 2; i <= x; i++) { sum *= i; } return sum; } ll p(ll x) { return (fact(x) / (2 * fact(x - 2))); } int main() { ll n, m; cin >> n >> m; cout << p(n) + p(m); } /* 100 100 */
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 1e5 + 7; ll p(ll x) { return (x * (x - 1) / 2); } int main() { ll n, m; cin >> n >> m; cout << p(n) + p(m); } /* 100 100 */
replace
4
12
4
6
0
p02729
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <float.h> #include <time.h> #define loop(i, start, end) for (i = (start); i <= (end); i++) #define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++) #define loopIteratorsRev(it, vec) \ for (it = (vec).rbegin(); it != (vec).rend(); it++) #define loopRev(i, start, end) for (i = (start); i >= (end); i--) #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testCases(t) \ cin >> t; \ while (t--) #define PN(n) cout << (n) #define PN1(n) cout << (n) << " " #define PN2(a, b) cout << (a) << " " << (b) << " " #define PNN1(n) cout << (n) << endl #define PNN2(a, b) cout << (a) << " " << (b) << endl #define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define PrintArray(ar, n) \ for (i = 0; i < n; i++) \ cout << ar[i] << " "; \ cout << endl #define PrintObject(ar, it) \ loopIterators(it, ar) cout << *it << " "; \ cout << endl #define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second) #define sz(a) sizeof(a) #define IN1(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define ALL(s) s.begin(), s.end() #define SWAP(a, b, c) \ c = a; \ a = b; \ b = c #define STRSP(s) scanf("%[^\n]%*c", s) #define ENTER PNN1(""); #define MOD7 1000000007 #define MOD9 10000009 #define MAX 1000000000 #define llPair std::pair<lli, lli> #define iiPair std::pair<int, int> // #define ONLINE_JUDGE typedef long long int lli; typedef long int li; typedef unsigned long long int ulli; typedef long double ld; using namespace std; int main(void) { FLASH #ifndef ONLINE_JUDGE freopen("input-stream.txt", "r", stdin); freopen("output-stream.txt", "w", stdout); #endif int a, b; IN2(a, b); int ans = a * (a - 1) / 2; ans += b * (b - 1) / 2; PNN1(ans); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <float.h> #include <time.h> #define loop(i, start, end) for (i = (start); i <= (end); i++) #define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++) #define loopIteratorsRev(it, vec) \ for (it = (vec).rbegin(); it != (vec).rend(); it++) #define loopRev(i, start, end) for (i = (start); i >= (end); i--) #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testCases(t) \ cin >> t; \ while (t--) #define PN(n) cout << (n) #define PN1(n) cout << (n) << " " #define PN2(a, b) cout << (a) << " " << (b) << " " #define PNN1(n) cout << (n) << endl #define PNN2(a, b) cout << (a) << " " << (b) << endl #define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define PrintArray(ar, n) \ for (i = 0; i < n; i++) \ cout << ar[i] << " "; \ cout << endl #define PrintObject(ar, it) \ loopIterators(it, ar) cout << *it << " "; \ cout << endl #define PrintMap(map, it) loopIterators(it, map) PNN2(it->first, it->second) #define sz(a) sizeof(a) #define IN1(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define ALL(s) s.begin(), s.end() #define SWAP(a, b, c) \ c = a; \ a = b; \ b = c #define STRSP(s) scanf("%[^\n]%*c", s) #define ENTER PNN1(""); #define MOD7 1000000007 #define MOD9 10000009 #define MAX 1000000000 #define llPair std::pair<lli, lli> #define iiPair std::pair<int, int> #define ONLINE_JUDGE typedef long long int lli; typedef long int li; typedef unsigned long long int ulli; typedef long double ld; using namespace std; int main(void) { FLASH #ifndef ONLINE_JUDGE freopen("input-stream.txt", "r", stdin); freopen("output-stream.txt", "w", stdout); #endif int a, b; IN2(a, b); int ans = a * (a - 1) / 2; ans += b * (b - 1) / 2; PNN1(ans); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
replace
63
64
63
64
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; float sumOfAP(float a, float d, float n) { float sum = (n / 2) * (2 * a + (n - 1) * d); return sum; } void solve() { int n, m; cin >> n >> m; int ans1 = sumOfAP(1, 1, n - 1); int ans2 = sumOfAP(1, 1, m - 1); cout << ans1 + ans2 << "\n"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; // cin>>t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; float sumOfAP(float a, float d, float n) { float sum = (n / 2) * (2 * a + (n - 1) * d); return sum; } void solve() { int n, m; cin >> n >> m; int ans1 = sumOfAP(1, 1, n - 1); int ans2 = sumOfAP(1, 1, m - 1); cout << ans1 + ans2 << "\n"; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif std::ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; // cin>>t; // while(t--) solve(); return 0; }
replace
22
26
22
26
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int factorial(int n) { // 階乗 long int ans = 0; long int ansa = 1; long int answ = 1; for (int i = 1; i <= n; i++) { ansa *= i; } for (int j = 1; j <= n - 2; j++) { answ *= j; } ans = ansa / (2 * answ); return ans; } int main() { int N = 0; // 偶数の数 int M = 0; // 奇数の数 int count1 = 0; int count2 = 0; cin >> N >> M; if (N != 0 && N != 1 && N != 2) { count1 = factorial(N); } else if (N == 2) { count1 = 1; } else { count1 = 0; } if (M != 0 && M != 1 && M != 2) { count2 = factorial(M); } else if (M == 2) { count2 = 1; } else { count2 = 0; } cout << count1 + count2 << endl; }
#include <bits/stdc++.h> using namespace std; int factorial(int n) { // 階乗 double ans = 0; double ansa = 1; double answ = 1; for (int i = 1; i <= n; i++) { ansa *= i; } for (int j = 1; j <= n - 2; j++) { answ *= j; } ans = ansa / (2 * answ); return ans; } int main() { int N = 0; // 偶数の数 int M = 0; // 奇数の数 int count1 = 0; int count2 = 0; cin >> N >> M; if (N != 0 && N != 1 && N != 2) { count1 = factorial(N); } else if (N == 2) { count1 = 1; } else { count1 = 0; } if (M != 0 && M != 1 && M != 2) { count2 = factorial(M); } else if (M == 2) { count2 = 1; } else { count2 = 0; } cout << count1 + count2 << endl; }
replace
4
7
4
7
0
p02729
C++
Runtime Error
/* Author: Shivam Shukla */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pair<ll, ll>> vpll; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; const double PI = acos(-1.0); const long double EPS = 1e-10; const int64_t INF = 1e18 + 10; #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(0), cout.tie(0) #define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vi vector<int> #define vl vector<ll> #define vs vector<str> #define vc(x) vector<x> #define mapll map<ll, ll> #define mapib map<int, bool> #define mapiv map<int, vector> #define mapsi map<string, int> #define rep(i, j, k) for (ll i = j; i < k; i++) #define down(i, j, k) for (ll i = j; i >= k; i--) #define repa(i, n) for (ll i = 0; i < n; i++) #define dowa(i, n) for (ll i = n; i >= 0; i--) #define reps(i, j, k, s) for (ll i = j; i < k; i += s) #define downs(i, j, k, s) for (ll i = j; i >= k; i -= s) #define trv(i, x) for (auto i : x) #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define ff first #define ss second #define str string #define dub double #define pqmax priority_queue<ll> #define pqmin priority_queue<ll, vl, greater<ll>> template <typename t> t lcm(t a, t b) { return (a * b) / __gcd(a, b); } template <typename t> t gcd(t a, t b) { return __gcd(a, b); } template <typename t> t mul_mod(t a, t b, t m) { t res = ((a % m) * (b % m) % m); return res; } template <typename t> t add_mod(t a, t b, t m) { t res = ((a % m) + (b % m)) % m; return res; } template <typename t> t pow_mod(t a, t b, t m) { t res = 1; while (b) { if (b & 1) res = mul_mod(res, a, m); a = mul_mod(a, a, m), b >>= 1; } return res % m; } template <typename t> vc(t) num_vec(t num) { t res; while (num) res.pb(num % 10), num /= 10; return res; } template <typename t> t vec_num(t vec) { t res = 0; ll mul = 1; repa(i, sz(vec)) res = vec[i] * mul, mul *= 10; return res; } int32_t main(int argc, char **argv) { fastio(); auto tstart = clock(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int n, m; cin >> n >> m; cout << ((n * (n - 1)) >> 1) + ((m * (m - 1)) >> 1) << endl; cerr << setprecision(2) << fixed << "Time elapsed: " << (double)(clock() - tstart) / CLOCKS_PER_SEC << endl; return 0; }
/* Author: Shivam Shukla */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pair<ll, ll>> vpll; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; const double PI = acos(-1.0); const long double EPS = 1e-10; const int64_t INF = 1e18 + 10; #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(0), cout.tie(0) #define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define vi vector<int> #define vl vector<ll> #define vs vector<str> #define vc(x) vector<x> #define mapll map<ll, ll> #define mapib map<int, bool> #define mapiv map<int, vector> #define mapsi map<string, int> #define rep(i, j, k) for (ll i = j; i < k; i++) #define down(i, j, k) for (ll i = j; i >= k; i--) #define repa(i, n) for (ll i = 0; i < n; i++) #define dowa(i, n) for (ll i = n; i >= 0; i--) #define reps(i, j, k, s) for (ll i = j; i < k; i += s) #define downs(i, j, k, s) for (ll i = j; i >= k; i -= s) #define trv(i, x) for (auto i : x) #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define ff first #define ss second #define str string #define dub double #define pqmax priority_queue<ll> #define pqmin priority_queue<ll, vl, greater<ll>> template <typename t> t lcm(t a, t b) { return (a * b) / __gcd(a, b); } template <typename t> t gcd(t a, t b) { return __gcd(a, b); } template <typename t> t mul_mod(t a, t b, t m) { t res = ((a % m) * (b % m) % m); return res; } template <typename t> t add_mod(t a, t b, t m) { t res = ((a % m) + (b % m)) % m; return res; } template <typename t> t pow_mod(t a, t b, t m) { t res = 1; while (b) { if (b & 1) res = mul_mod(res, a, m); a = mul_mod(a, a, m), b >>= 1; } return res % m; } template <typename t> vc(t) num_vec(t num) { t res; while (num) res.pb(num % 10), num /= 10; return res; } template <typename t> t vec_num(t vec) { t res = 0; ll mul = 1; repa(i, sz(vec)) res = vec[i] * mul, mul *= 10; return res; } int32_t main(int argc, char **argv) { fastio(); auto tstart = clock(); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif */ int n, m; cin >> n >> m; cout << ((n * (n - 1)) >> 1) + ((m * (m - 1)) >> 1) << endl; cerr << setprecision(2) << fixed << "Time elapsed: " << (double)(clock() - tstart) / CLOCKS_PER_SEC << endl; return 0; }
replace
86
91
86
91
0
p02729
C++
Runtime Error
#include <iostream> using namespace std; int main() { int N, M; cin >> N >> M; int ans = 0; if (M == 0 || M == 1) { ans = 0; } else { ans = M; } if (N == 0 || N == 1) { ans += 0; } else { long f = 1; for (long i = 1; i <= N; i++) f *= i; long n = f; f = 1; for (long i = 1; i <= N - 2; i++) f *= i; long nr = f; ans += n / (2 * nr); } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N, M; cin >> N >> M; int ans = 0; ans = N * (N - 1) / 2 + M * (M - 1) / 2; cout << ans << endl; }
replace
10
31
10
11
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } int main() { int n, m; cin >> n >> m; cout << nCr(n, 2) + nCr(m, 2); }
#include <bits/stdc++.h> using namespace std; int fact(int n) { int res = 1; for (int i = 2; i <= n; i++) res = res * i; return res; } int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); } int main() { int n, m; cin >> n >> m; cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2; }
replace
15
16
15
16
0
p02729
C++
Runtime Error
#include <iostream> int main() { using namespace std; long N, M; cin >> N >> M; int result = N * (N - 1) / 2 + M * (M - 1) / 2; cout << result << endl; return 1; }
#include <iostream> int main() { using namespace std; long N, M; cin >> N >> M; int result = N * (N - 1) / 2 + M * (M - 1) / 2; cout << result << endl; return 0; }
replace
11
12
11
12
1
p02729
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <list> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define ll long long #define INF 0x3f3f3f3f #define SIS std::ios::sync_with_stdio(false) using namespace std; ll fast_pow(ll a, ll b, ll mod) { ll c = 1; while (b >= 2) { if (b % 2 == 0) a *= a, b /= 2; else c *= a, a *= a, b--, b /= 2; a %= mod, c %= mod; } return (a * c) % mod; } ll cal(ll n, ll m); int main() { int n, m; while (cin >> n >> m) { ll ans = 0; if (n > 1) ans += cal(n, 2); if (m > 1) ans += cal(m, 2); cout << ans << endl; } return 0; } ll cal(ll n, ll m) { ll up = 1, a = 1, b = 1, c = n - m; for (ll i = 1; i <= n; i++) up *= i; for (ll i = 1; i <= m; i++) a *= i; for (ll i = 1; i <= c; i++) b *= i; return up / a / b; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <list> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define ll long long #define INF 0x3f3f3f3f #define SIS std::ios::sync_with_stdio(false) using namespace std; ll fast_pow(ll a, ll b, ll mod) { ll c = 1; while (b >= 2) { if (b % 2 == 0) a *= a, b /= 2; else c *= a, a *= a, b--, b /= 2; a %= mod, c %= mod; } return (a * c) % mod; } ll cal(ll n, ll m); int main() { int n, m; while (cin >> n >> m) { ll ans = 0; if (n > 1) ans += cal(n, 2); if (m > 1) ans += cal(m, 2); cout << ans << endl; } return 0; } ll cal(ll n, ll m) { return n * (n - 1) / 2; }
replace
41
51
41
42
0
p02729
C++
Runtime Error
#include <iostream> using namespace std; int fact(int n) { if (n <= 1) return 1; else return n * fact(n - 1); } int result(int e, int o) { int odd = fact(o) / (2 * fact(o - 2)); int even = fact(e) / (2 * fact(e - 2)); return odd + even; } int main() { int even_no, odd_no; cin >> even_no >> odd_no; cout << result(even_no, odd_no); }
#include <iostream> using namespace std; int fact(int n) { if (n <= 1) return 1; else return n * fact(n - 1); } int result(int e, int o) { int odd = o * (o - 1) / 2; int even = e * (e - 1) / 2; return odd + even; } int main() { int even_no, odd_no; cin >> even_no >> odd_no; cout << result(even_no, odd_no); }
replace
9
11
9
11
0
p02729
C++
Time Limit Exceeded
//??????????SM?????????? // -------------Sourav Mondal---------- // _____________________________________"GUN IS ON FIRE~SM" //..._|.._|___________________, ,) ----) "KILL YOUR headache Shoot iT" //....../ `---___________----_____|]_____) ********* 2eZ4@SM //...../_==o;;;;;;;;_______.:/ //.....), ---.(_(__) / ask2sm********* //....// (.||_.) ), ----" //...//___// //../|___/| //.||___|| //---------------------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; #define llt long long int #define pb(x) push_back(x) int printNcR(int n, int r) { // p holds the value of n*(n-1)*(n-2)..., // k holds the value of r*(r-1)... long long p = 1, k = 1; // C(n, r) == C(n, n-r), // choosing the smaller value if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; // gcd of p, k long long m = __gcd(p, k); // dividing by gcd, to simplify product // division by their gcd saves from the overflow p /= m; k /= m; n--; r--; } // k should be simplified to 1 // as C(n, r) is a natural number // (denominator should be 1 ) . } else p = 1; return p; } int main() { int n, m; cin >> n >> m; if (n < 2 && m >= 2) { cout << printNcR(m, 2) << endl; return 0; } else if (m < 2 && n >= 2) { cout << printNcR(n, 2) << endl; return 0; } cout << printNcR(n, 2) + printNcR(m, 2) << endl; int count = 0; }
//??????????SM?????????? // -------------Sourav Mondal---------- // _____________________________________"GUN IS ON FIRE~SM" //..._|.._|___________________, ,) ----) "KILL YOUR headache Shoot iT" //....../ `---___________----_____|]_____) ********* 2eZ4@SM //...../_==o;;;;;;;;_______.:/ //.....), ---.(_(__) / ask2sm********* //....// (.||_.) ), ----" //...//___// //../|___/| //.||___|| //---------------------------------------------------------------------------- #include <bits/stdc++.h> using namespace std; #define llt long long int #define pb(x) push_back(x) int printNcR(int n, int r) { // p holds the value of n*(n-1)*(n-2)..., // k holds the value of r*(r-1)... long long p = 1, k = 1; // C(n, r) == C(n, n-r), // choosing the smaller value if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; // gcd of p, k long long m = __gcd(p, k); // dividing by gcd, to simplify product // division by their gcd saves from the overflow p /= m; k /= m; n--; r--; } // k should be simplified to 1 // as C(n, r) is a natural number // (denominator should be 1 ) . } else p = 1; return p; } int main() { int n, m; cin >> n >> m; if (n == 1 && m == 1) { cout << 0 << endl; return 0; } if (n < 2 && m >= 2) { cout << printNcR(m, 2) << endl; return 0; } else if (m < 2 && n >= 2) { cout << printNcR(n, 2) << endl; return 0; } cout << printNcR(n, 2) + printNcR(m, 2) << endl; int count = 0; }
insert
60
60
60
64
TLE
p02729
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; const int MAX = 1e6; const int INF = 2e9; typedef long long ll; int comb(int n, int r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } int x = 1; int y = 1; for (int i = 0; i < n - r; ++i) { x = x * (n - i); y = y * (i + 1); } return x / y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; cout << comb(n, 2) + comb(m, 2); return 0; }
#include <algorithm> #include <iostream> using namespace std; const int MAX = 1e6; const int INF = 2e9; typedef long long ll; int comb(int n, int r) { if (n < r) { return 0; } if (n == r || r == 0) { return 1; } int x = 1; int y = 1; for (int i = 0; i < r; ++i) { x = x * (n - i); y = y * (i + 1); } return x / y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; cout << comb(n, 2) + comb(m, 2); return 0; }
replace
21
22
21
22
0
p02729
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m; scanf("%d %d", n, m); printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2); }
#include <iostream> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2); }
replace
4
5
4
5
-11
p02729
C++
Runtime Error
/* SANDEEP YADAv*/ #include <bits/stdc++.h> using namespace std; #define lld long long int #define pb push_back #define mkp make_pair #define fi first #define se second #define mod 1000000007 #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) lld gcd(lld a, lld b) { if (a < b) { a = a + b; b = a - b; a = a - b; } while (b != 0) { lld r = a % b; a = b; b = r; } return a; } long long power(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } void judge() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { fastio; judge(); lld n, m; cin >> n >> m; cout << n * (n - 1) / 2 + m * (m - 1) / 2; return 0; }
/* SANDEEP YADAv*/ #include <bits/stdc++.h> using namespace std; #define lld long long int #define pb push_back #define mkp make_pair #define fi first #define se second #define mod 1000000007 #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) lld gcd(lld a, lld b) { if (a < b) { a = a + b; b = a - b; a = a - b; } while (b != 0) { lld r = a % b; a = b; b = r; } return a; } long long power(long long a, long long b, long long m) { a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } void judge() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { fastio; // judge(); lld n, m; cin >> n >> m; cout << n * (n - 1) / 2 + m * (m - 1) / 2; return 0; }
replace
47
48
47
48
0
p02729
C++
Runtime Error
// Template // #include <bits/stdc++.h> using namespace std; // マクロ // #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define uniq(x) x.erase(unique(all(x)), x.end()) #define vsum(x) accumulate(all(x), 0) #define cou(x) cout << x << endl #define y() cout << "Yes" << endl #define n() cout << "No" << endl #define Y() cout << "YES" << endl #define N() cout << "NO" << endl #define x2(x) (x) * (x) // 型エイリアス // using lint = long long; using pii = pair<int, int>; using vi = vector<int>; using vli = vector<lint>; using vc = vector<char>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; using vvb = vector<vb>; using vvc = vector<vc>; using vpii = vector<pii>; using msi = map<string, int>; // 関数 // int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; } return a; } int lcm(int a, int b) { return a * b / gcd(a, b); } double distance(pii a, pii b) { double dist; dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second)); return dist; } lint perm(int a) { lint perm = 1; for (int i = a; i >= 1; i--) { perm *= i; } return perm; } lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); } // 定数 // #define pi acos(-1) // End of Template // int main() { cin.tie(0); ios::sync_with_stdio(false); lint N, M; cin >> N >> M; cou(comb(N, 2) + comb(M, 2)); }
// Template // #include <bits/stdc++.h> using namespace std; // マクロ // #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define uniq(x) x.erase(unique(all(x)), x.end()) #define vsum(x) accumulate(all(x), 0) #define cou(x) cout << x << endl #define y() cout << "Yes" << endl #define n() cout << "No" << endl #define Y() cout << "YES" << endl #define N() cout << "NO" << endl #define x2(x) (x) * (x) // 型エイリアス // using lint = long long; using pii = pair<int, int>; using vi = vector<int>; using vli = vector<lint>; using vc = vector<char>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; using vvb = vector<vb>; using vvc = vector<vc>; using vpii = vector<pii>; using msi = map<string, int>; // 関数 // int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; } return a; } int lcm(int a, int b) { return a * b / gcd(a, b); } double distance(pii a, pii b) { double dist; dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second)); return dist; } lint perm(int a) { lint perm = 1; for (int i = a; i >= 1; i--) { perm *= i; } return perm; } lint comb(lint n, lint m) { return perm(n) / (perm(n - m) * perm(m)); } // 定数 // #define pi acos(-1) // End of Template // int main() { cin.tie(0); ios::sync_with_stdio(false); lint N, M; cin >> N >> M; cou(N * (N - 1) / 2 + M * (M - 1) / 2); }
replace
72
73
72
73
0
p02729
C++
Runtime Error
// file creato da gio il 2020-03-25 09:50:14.759573 #include <bits/stdc++.h> #define FAST #ifdef FAST #pragma GCC optimize("Ofast") #pragma GCC target( \ "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #endif #define S second #define F first #define PB push_back using namespace std; int counter(int n) { int sum = 0; for (int i = 1; i < n; i++) { sum += (n - i); } return sum; } int main() { // freopen("output","w",stdout); // freopen("input","r",stdin); #ifdef FAST ios::sync_with_stdio(0); cin.tie(0); #endif int N, M; cin >> N >> M; cout << counter(N) + counter(M) << endl; }
// file creato da gio il 2020-03-25 09:50:14.759573 #include <bits/stdc++.h> #define FAST #ifdef FAST #pragma GCC optimize("Ofast") #pragma GCC target( \ "fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #endif #define S second #define F first #define PB push_back using namespace std; int counter(int n) { return n * (n - 1) / 2; } int main() { // freopen("output","w",stdout); // freopen("input","r",stdin); #ifdef FAST ios::sync_with_stdio(0); cin.tie(0); #endif int N, M; cin >> N >> M; cout << counter(N) + counter(M) << endl; }
replace
17
24
17
18
0
p02729
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; long long int i = 1; long long int j = 1; long long int p1 = 1; long long int p2 = 1; long long int c1 = n - 2; long long int c2 = m - 2; if (n + m >= 2) { while (n > 0) { i = n * i; n--; } while (m > 0) { j = m * j; m--; } if (c1 >= 0 && c2 >= 0) { while (c1 > 0) { p1 = c1 * p1; c1--; } while (c2 > 0) { p2 = c2 * p2; c2--; } } } p2 = p2 * 2; p1 = p1 * 2; int o; o = i / p1; int o1; o1 = j / p2; cout << o1 + o; return 0; }
#include <iostream> using namespace std; int main() { int n, m; cin >> n >> m; cout << n * (n - 1) / 2 + m * (m - 1) / 2; return 0; }
replace
5
44
5
6
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", n, m); printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2); return 0; }
replace
6
7
6
7
-11
p02729
C++
Time Limit Exceeded
#include <iostream> using namespace std; int kaijou(int a) { return a * kaijou(a - 1); } int main() { int N, M; cin >> N >> M; N = kaijou(N) / 2; M = kaijou(M) / 2; cout << N + M << endl; }
#include <iostream> using namespace std; int kaijou(int a) { return a * (a - 1); } int main() { int N, M; cin >> N >> M; N = kaijou(N) / 2; M = kaijou(M) / 2; cout << N + M << endl; }
replace
3
4
3
4
TLE
p02729
C++
Runtime Error
// by The_One_Solver #include <bits/stdc++.h> #include <iostream> using namespace std; long long n, m, f = 1, c = 1, h = 1, odd = 1; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) { c *= i; if (i <= (n - 2)) f *= i; } for (int i = 1; i <= m; i++) { odd *= i; if (i <= m - 2) h *= i; } cout << (c / (f * 2)) + (odd / (h * 2)); return 0; }
// by The_One_Solver #include <bits/stdc++.h> #include <iostream> using namespace std; long long n, m, f = 1, c = 1, h = 1, odd = 1; int main() { cin >> n >> m; cout << (n > 1 ? (n * (n - 1)) / 2 : 0) + (m > 1 ? (m * (m - 1)) / 2 : 0) << endl; }
replace
8
20
8
11
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int all = 1; int A = 1; for (int i = 1; i <= N + M; i++) { all *= i; } if (N + M == 2) { A = 1; } else { for (int i = 1; i <= N + M - 2; i++) { A *= i; } } cout << all / 2 / A - N * M << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; cout << (N * N + M * M - N - M) / 2 << endl; }
replace
6
23
6
7
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define x first #define y second #define pb push_back #define endl "\n" ll fact(int a) { if (a == 0) return 1; return a * fact(a - 1); } using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; ll ans = 0; cout << fact(n) / (2 * fact(n - 2)) + fact(m) / (2 * fact(m - 2)); return 0; }
#include <bits/stdc++.h> #define ll long long #define x first #define y second #define pb push_back #define endl "\n" ll fact(int a) { if (a == 0) return 1; return a * fact(a - 1); } using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, m; cin >> n >> m; cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2; return 0; }
replace
18
20
18
20
-11
p02729
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { cin >> n >> m; x = n * (n - 1) / 2 + m * (m - 1) / 2; cout << x; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ int main() { _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { cin >> n >> m; x = n * (n - 1) / 2 + m * (m - 1) / 2; cout << x; } return 0; }
delete
55
60
55
55
0
p02729
C++
Runtime Error
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, cnt, a[100]; cin >> n >> m; for (int i = 0; i < n; i++) { a[i] = i * 2; } for (int j = n; j < n + m; j++) { a[j] = j * 2 + 1; } for (int k = 0; k < n + m; k++) { for (int l = k + 1; l < n + m; l++) { if ((a[k] + a[l]) % 2 != 0) { continue; } else { cnt++; }; } } cout << cnt << "\n"; return 0; }
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m, cnt, a[n + m]; cin >> n >> m; for (int i = 0; i < n; i++) { a[i] = i * 2; } for (int j = n; j < n + m; j++) { a[j] = j * 2 + 1; } for (int k = 0; k < n + m; k++) { for (int l = k + 1; l < n + m; l++) { if ((a[k] + a[l]) % 2 != 0) { continue; } else { cnt++; }; } } cout << cnt << "\n"; return 0; }
replace
6
7
6
7
0
p02729
C++
Time Limit Exceeded
#include <stdio.h> int main() { int N; // even int M; // odd unsigned sum; while (scanf("%d%d", &N, &M)) { sum = (N * N + M * M - M - N) >> 1; printf("%d\n", sum); } }
#include <stdio.h> int main() { int N; // even int M; // odd unsigned sum; scanf("%d%d", &N, &M); sum = (N * N + M * M - M - N) >> 1; printf("%d\n", sum); }
replace
5
9
5
8
TLE
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int a = 1, b = 1, c = 1, d = 1; for (int i = 1; i < N + 1; i++) a *= i; for (int i = N; i > 0; i--) { if (N <= 1) b = 0; else b *= i; } for (int j = 1; j < M + 1; j++) c *= j; for (int j = M; j > 0; j--) { if (M <= 1) d = 0; else d *= j; } cout << b / a + d / c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl; }
replace
5
23
5
6
0
p02729
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; #define int long long #define val(x) cout << #x << " equals to " << x << endl #define F first #define S second #define pb push_back const int N = 2e6 + 7; const int INF = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifndef ONLINE_JUDGE freopen("/home/emrey/Coding/IO/in.txt", "r", stdin); // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout); #endif int n, m; cin >> n >> m; cout << ((n * (n - 1) / 2) + (m * (m - 1) / 2)) << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> using namespace std; #define int long long #define val(x) cout << #x << " equals to " << x << endl #define F first #define S second #define pb push_back const int N = 2e6 + 7; const int INF = 1e18; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifndef ONLINE_JUDGE // freopen("/home/emrey/Coding/IO/in.txt", "r", stdin); // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout); #endif int n, m; cin >> n >> m; cout << ((n * (n - 1) / 2) + (m * (m - 1) / 2)) << endl; }
replace
28
29
28
29
0
p02729
Python
Runtime Error
import math def f(x): return math.factorial(x) arr = list(map(int, input().split())) n = arr[0] m = arr[1] cnt = 0 cnt += int(f(n) / (2 * f(n - 2))) if m > 1: cnt += int(f(m) / (2 * f(m - 2))) print(int(cnt))
n, m = map(int, input().split()) print((n * (n - 1)) // 2 + (m * (m - 1)) // 2)
replace
0
15
0
2
0
p02729
Python
Runtime Error
N, M = map(int, input().split()) print(N(N - 1) // 2 + M(M - 1) // 2)
N, M = map(int, input().split()) print(N * (N - 1) // 2 + M * (M - 1) // 2)
replace
2
3
2
3
TypeError: 'int' object is not callable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s193391695.py", line 3, in <module> print(N(N - 1) // 2 + M(M - 1) // 2) TypeError: 'int' object is not callable
p02729
Python
Runtime Error
import math n, m = map(int, input().split()) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) ans = combinations_count(m, 2) + combinations_count(n, 2) print(ans)
import math n, m = map(int, input().split()) def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) if n >= 2 and m >= 2: ans = combinations_count(m, 2) + combinations_count(n, 2) elif n < 2 and m < 2: ans = 0 elif n < 2: ans = combinations_count(m, 2) elif m < 2: ans = combinations_count(n, 2) print(ans)
replace
9
10
9
18
ValueError: factorial() not defined for negative values
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s072089097.py", line 10, in <module> ans = combinations_count(m, 2) + combinations_count(n, 2) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s072089097.py", line 7, in combinations_count return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) ValueError: factorial() not defined for negative values
p02729
Python
Runtime Error
from scipy.special import comb n, m = map(int, input().split()) # nC2+mC2を求めればよい print(comb(n, 2, exact=True) + comb(m, 2, exact=True))
from scipy.misc import comb n, m = map(int, input().split()) # nC2+mC2を求めればよい print(comb(n, 2, exact=True) + comb(m, 2, exact=True))
replace
0
1
0
1
ModuleNotFoundError: No module named 'scipy'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s068360143.py", line 1, in <module> from scipy.special import comb ModuleNotFoundError: No module named 'scipy'
p02729
Python
Runtime Error
import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def main(): n, m = map(int, input().split()) print(combinations_count(n, 2) + combinations_count(m, 2)) if __name__ == "__main__": main()
import math def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def main(): n, m = map(int, input().split()) if n < 2: even = 0 else: even = combinations_count(n, 2) if m < 2: odd = 0 else: odd = combinations_count(m, 2) print(even + odd) if __name__ == "__main__": main()
replace
9
10
9
18
ValueError: factorial() not defined for negative values
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 14, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 10, in main print(combinations_count(n, 2) + combinations_count(m, 2)) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s584253829.py", line 5, in combinations_count return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) ValueError: factorial() not defined for negative values
p02729
Python
Runtime Error
N, M = list(int, input().split()) print(int(N * (N - 1) / 2 + M * (M - 1) / 2))
N, M = map(int, input().split()) print(int(N * (N - 1) / 2 + M * (M - 1) / 2))
replace
0
1
0
1
TypeError: list expected at most 1 argument, got 2
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s321382416.py", line 1, in <module> N, M = list(int, input().split()) TypeError: list expected at most 1 argument, got 2
p02729
C++
Runtime Error
/* Author- Aasav Badera Time- Sun Mar 22 17:30:45 2020 */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define mii map<ll, ll> #define dbg(x) \ { cerr << #x << ": " << x << endl; } #define dbg2(x, y) \ { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; } #define rep(i, a, b) for (ll i = a; i < b; i++) #define pii pair<ll, ll> #define ppb pop_back #define f first #define vi vector<ll> #define vii vector<pair<ll, ll>> #define si set<ll> #define all(a) (a).begin(), (a).end() #define sz(x) (ll) x.size() #define hell 1000000007 #define mp make_pair #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define inf 1e18L + 1 #define endl '\n' using namespace std; #define N 300005 int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif ll tests = 1; // cin >> tests; while (tests--) { ll n, m; cin >> n >> m; ll ans = n * (n - 1) + m * (m - 1); ans /= 2; cout << ans; } return 0; }
/* Author- Aasav Badera Time- Sun Mar 22 17:30:45 2020 */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define mii map<ll, ll> #define dbg(x) \ { cerr << #x << ": " << x << endl; } #define dbg2(x, y) \ { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; } #define rep(i, a, b) for (ll i = a; i < b; i++) #define pii pair<ll, ll> #define ppb pop_back #define f first #define vi vector<ll> #define vii vector<pair<ll, ll>> #define si set<ll> #define all(a) (a).begin(), (a).end() #define sz(x) (ll) x.size() #define hell 1000000007 #define mp make_pair #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define inf 1e18L + 1 #define endl '\n' using namespace std; #define N 300005 int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll tests = 1; // cin >> tests; while (tests--) { ll n, m; cin >> n >> m; ll ans = n * (n - 1) + m * (m - 1); ans /= 2; cout << ans; } return 0; }
delete
35
41
35
35
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> // definitions #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++) #define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--) #define pb push_back #define pf push_front #define mod1 998244353 #define mod 1000000007 #define MAX_CHAR 256 using namespace std; typedef vector<long long> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pair<long long, long long>> vp; typedef vector<tuple<long long, long long, long long>> vtup; typedef deque<long long> dql; typedef deque<char> dqc; typedef long double ld; typedef long long ll; typedef unsigned long long ull; // prevent collisions in unordered_map struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; typedef unordered_map<long long, long long, custom_hash> umap; // standard functions ll mystoi(string str) { stringstream ss(str); ll ans = 0; ss >> ans; return ans; } ll exp(ll x, ll ex) { ll ans = 1ll; while (ex > 0) { if (ex & 1ll) ans = (ans * x); ex >>= 1ll; x = (x * x); } return ans; } ll nCrModp(ll n, ll r, ll p) { ll C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } bool sort_cond(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.second > b.second; } const ll MAXSIEVE = (1e3 + 5); ll spf[MAXSIEVE]; void sieve() { spf[1] = 1; for (ll i = 2; i < MAXSIEVE; i++) spf[i] = i; for (ll i = 4; i < MAXSIEVE; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXSIEVE; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXSIEVE; j += i) if (spf[j] == j) spf[j] = i; } } } // code beigns in main int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while (t--) { ll m, n; cin >> m >> n; cout << nCrModp(m, 2, 1e18) + nCrModp(n, 2, 1e18) << endl; } }
#include <bits/stdc++.h> // definitions #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++) #define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--) #define pb push_back #define pf push_front #define mod1 998244353 #define mod 1000000007 #define MAX_CHAR 256 using namespace std; typedef vector<long long> vl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<pair<long long, long long>> vp; typedef vector<tuple<long long, long long, long long>> vtup; typedef deque<long long> dql; typedef deque<char> dqc; typedef long double ld; typedef long long ll; typedef unsigned long long ull; // prevent collisions in unordered_map struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; typedef unordered_map<long long, long long, custom_hash> umap; // standard functions ll mystoi(string str) { stringstream ss(str); ll ans = 0; ss >> ans; return ans; } ll exp(ll x, ll ex) { ll ans = 1ll; while (ex > 0) { if (ex & 1ll) ans = (ans * x); ex >>= 1ll; x = (x * x); } return ans; } ll nCrModp(ll n, ll r, ll p) { ll C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p; } return C[r]; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } bool sort_cond(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.second > b.second; } const ll MAXSIEVE = (1e3 + 5); ll spf[MAXSIEVE]; void sieve() { spf[1] = 1; for (ll i = 2; i < MAXSIEVE; i++) spf[i] = i; for (ll i = 4; i < MAXSIEVE; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXSIEVE; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXSIEVE; j += i) if (spf[j] == j) spf[j] = i; } } } // code beigns in main int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; // cin >> t; while (t--) { ll m, n; cin >> m >> n; cout << nCrModp(m, 2, 1e18) + nCrModp(n, 2, 1e18) << endl; } }
delete
118
123
118
118
TLE
p02729
C++
Runtime Error
#include <stdio.h> int main() { int N, M; int Ball[201]; freopen("input.txt", "r", stdin); scanf("%d %d", &N, &M); int BallCnt = 0; for (int n = 1; n <= N; n++) // even Ball[BallCnt++] = 2 * n; for (int m = 0; m < M; m++) // odd Ball[BallCnt++] = 2 * m + 1; int ResultCnt = 0; for (int b = 0; b < BallCnt; b++) for (int t = 0; t < BallCnt; t++) if (b != t) if ((Ball[b] + Ball[t]) % 2 == 0) ResultCnt++; printf("%d", ResultCnt / 2); return 0; }
#include <stdio.h> int main() { int N, M; int Ball[201]; scanf("%d %d", &N, &M); int BallCnt = 0; for (int n = 1; n <= N; n++) // even Ball[BallCnt++] = 2 * n; for (int m = 0; m < M; m++) // odd Ball[BallCnt++] = 2 * m + 1; int ResultCnt = 0; for (int b = 0; b < BallCnt; b++) for (int t = 0; t < BallCnt; t++) if (b != t) if ((Ball[b] + Ball[t]) % 2 == 0) ResultCnt++; printf("%d", ResultCnt / 2); return 0; }
delete
5
7
5
5
-11
p02729
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, m, n) for (int i = m; i < n; i++) #define repr(i, n, m) for (int i = n; i >= m; i--) #define mod 1000000007 #define float long double #define pb push_back #define mp make_pair using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } int binomialCoeff(int n, int k) { // Base Cases if (k == 0 || k == n) return 1; // Recur return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k); } void solve() { int n, m, total = 0; cin >> n >> m; if (n > 1) total += binomialCoeff(n, 2); if (m > 1) total += binomialCoeff(m, 2); cout << total; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while (t--) { solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, m, n) for (int i = m; i < n; i++) #define repr(i, n, m) for (int i = n; i >= m; i--) #define mod 1000000007 #define float long double #define pb push_back #define mp make_pair using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } int binomialCoeff(int n, int k) { // Base Cases if (k == 0 || k == n) return 1; // Recur return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k); } void solve() { int n, m, total = 0; cin >> n >> m; if (n > 1) total += binomialCoeff(n, 2); if (m > 1) total += binomialCoeff(m, 2); cout << total; } signed main() { int t = 1; // cin>>t; while (t--) { solve(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
replace
34
41
34
35
-11
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, a, ans; cin >> n >> m; if (n == 1 && m == 1) cout << "0" << endl; else if ((n + m) % 2 != 0) { a = n / m + 1; ans = pow(m, a); cout << ans << endl; } else { a = n / m; ans = pow(m, a); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, M, ans; cin >> N >> M; ans = N * (N - 1) / 2 + M * (M - 1) / 2; cout << ans << endl; return 0; }
replace
3
16
3
7
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(p, a, b) for (int p = a; p < b; p++) #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define INF 0x3f3f3f3f int C(int n, int r) { int ans = 1; if (r > n - r) r = n - r; for (int i = 0; i < r; i++) { ans *= ((n - i) / (i + 1)); } return ans; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("o2.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k, i, t, ans = 0; cin >> n >> k; if (n) ans = n * (n - 1) / 2; if (k) ans += k * (k - 1) / 2; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(p, a, b) for (int p = a; p < b; p++) #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() #define INF 0x3f3f3f3f int C(int n, int r) { int ans = 1; if (r > n - r) r = n - r; for (int i = 0; i < r; i++) { ans *= ((n - i) / (i + 1)); } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k, i, t, ans = 0; cin >> n >> k; if (n) ans = n * (n - 1) / 2; if (k) ans += k * (k - 1) / 2; cout << ans; return 0; }
delete
21
29
21
21
0
p02729
Python
Runtime Error
while True: m, n = list(map(int, input().split())) print(m * (m - 1) / 2 + n * (n - 1) / 2)
m, n = list(map(int, input().split())) print(int(m * (m - 1) / 2 + n * (n - 1) / 2))
replace
0
3
0
2
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02729/Python/s164214433.py", line 2, in <module> m, n = list(map(int, input().split())) EOFError: EOF when reading a line
p02729
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // Returns value of Binomial Coefficient C(n, k) int binomialCoeff(int n, int k) { // Base Cases if (k == 0 || k == n) return 1; // Recur return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k); } /* Driver code*/ int main() { int n, m; cin >> n >> m; int x; x = binomialCoeff(n, 2) + binomialCoeff(m, 2); cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // Returns value of Binomial Coefficient C(n, k) int binomialCoeff(int n, int k) { // Base Cases if (k == 0 || k == n) return 1; // Recur return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k); } /* Driver code*/ int main() { int n, m; cin >> n >> m; int x; if ((n == 0 || n == 1) && (m == 0 || m == 1)) x = 0; else if (n == 0 || n == 1) x = binomialCoeff(m, 2); else if (m == 0 || m == 1) x = binomialCoeff(n, 2); else x = binomialCoeff(n, 2) + binomialCoeff(m, 2); cout << x << endl; return 0; }
replace
18
19
18
26
TLE
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); long long fact(int x) { if (x == 0) return 1; else return x * fact(x - 1); } long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); } int main() { fast; int n, m; long long p, q; cin >> n >> m; if (n >= 2) p = permu(n, 2); else p = n / 2; if (m >= 2) q = permu(m, 2); else q = m / 2; cout << p + q; }
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); long long fact(int x) { if (x == 0) return 1; else return x * fact(x - 1); } long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); } int main() { fast; int n, m; long long p, q; cin >> n >> m; cout << ((n - 1) * n) / 2 + (m * (m - 1)) / 2; }
replace
18
27
18
19
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define lh long double #define f(a, b, i) for (ll i = a; i < b; i++) int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; cout << (n * (n - 1) + m * (m - 1)) / 2; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define lh long double #define f(a, b, i) for (ll i = a; i < b; i++) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, m; cin >> n >> m; cout << (n * (n - 1) + m * (m - 1)) / 2; return 0; }
delete
8
12
8
8
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> /* #include <boost/math/common_factor.hpp> boost::math::lcm(10,20) ---> use it to find lcm.*/ using namespace std; #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef long long ll; #define PI pair<int, int> #define mpr make_pair #define ff first #define ss second #define endl "\n" #define pb push_back const int MOD = 1e9 + 7; const int MAXN = 1e5 + 3; const int inf = 2e9; /************ Use when precision need to set to some value **************/ // std::cout << std::setprecision(12); // std::cout << std::fixed; /*******************************************/ int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } /* 0. Go to main function first. 1. Take all the inputs................................................ 2. Check Once whether the graph given is directed or undirected....... 3. Tree can also be undirected. 4. Whenever you do multiplication and division in the same line, beware. */ void solve() { int n, m; cin >> n >> m; int ans = 0; ans += ((n * (n - 1)) / 2); ans += ((m * (m - 1)) / 2); cout << ans << endl; } /* memset() can be used to set all values as 0 or -1 for integer data types. It will not work if we use it to set as other values. The reason is memset works byte by byte. */ int main() { IO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ONLINE_JUDGE int t; // cin >> t; t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> /* #include <boost/math/common_factor.hpp> boost::math::lcm(10,20) ---> use it to find lcm.*/ using namespace std; #define IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) typedef long long ll; #define PI pair<int, int> #define mpr make_pair #define ff first #define ss second #define endl "\n" #define pb push_back const int MOD = 1e9 + 7; const int MAXN = 1e5 + 3; const int inf = 2e9; /************ Use when precision need to set to some value **************/ // std::cout << std::setprecision(12); // std::cout << std::fixed; /*******************************************/ int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } /* 0. Go to main function first. 1. Take all the inputs................................................ 2. Check Once whether the graph given is directed or undirected....... 3. Tree can also be undirected. 4. Whenever you do multiplication and division in the same line, beware. */ void solve() { int n, m; cin >> n >> m; int ans = 0; ans += ((n * (n - 1)) / 2); ans += ((m * (m - 1)) / 2); cout << ans << endl; } /* memset() can be used to set all values as 0 or -1 for integer data types. It will not work if we use it to set as other values. The reason is memset works byte by byte. */ int main() { IO; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif // ONLINE_JUDGE int t; // cin >> t; t = 1; while (t--) { solve(); } return 0; }
replace
62
66
62
66
0
p02729
C++
Runtime Error
// HYSO SERIOUS? WHY SO SERIOUS RIOUS? WHY //SO SERIOUS? WHYSO SERIO ERIOUS? WHY SO SERIOUS ? WHY WHY SO SERIOUS? WHY //SOSERIOUSWHYS OSERIOUS? WHY SO SERIOU SERIOUS ERIOUS? WHY SO //SERIOUS? WHYS WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY //SO SE ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO WHY //SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH SERIOUS?WHYSO //SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE ?WHYSOSERIOUS?WHY SO //SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS? OSERIOUS? WHY SO SERIOUS?WHYSOSER // HYSOSERIOUS?WHYSOSERI // SOSERIOUS?W // SER // W #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; #include <algorithm> #include <bits/stdc++.h> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define v(pi) vector<ll> pi #define vp(pi) vector<pair<ll, ll>> pi #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #include <cmath> #include <map> #include <string> #define mi(lol) map<ll, ll> lol #define fsort(vec) sort(vec.begin(), vec.end()) #define rsort(vec) sort(vec.begin(), vec.end(), compare) #define inf ll inf = INT_MAX // sorting according to the second element vector bool compare(pair<ll, ll> p, pair<ll, ll> q) { return p.second < q.second; } // example:- // sort(vec.begin(),vec.end(),compare); int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif read(a) read(b) ll m = a * (a - 1) / 2; ll n = b * (b - 1) / 2; cout << m + n << endl; return 0; }
// HYSO SERIOUS? WHY SO SERIOUS RIOUS? WHY //SO SERIOUS? WHYSO SERIO ERIOUS? WHY SO SERIOUS ? WHY WHY SO SERIOUS? WHY //SOSERIOUSWHYS OSERIOUS? WHY SO SERIOU SERIOUS ERIOUS? WHY SO //SERIOUS? WHYS WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY //SO SE ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO WHY //SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH SERIOUS?WHYSO //SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE ?WHYSOSERIOUS?WHY SO //SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS? OSERIOUS? WHY SO SERIOUS?WHYSOSER // HYSOSERIOUS?WHYSOSERI // SOSERIOUS?W // SER // W #include <iostream> #include <queue> #include <tuple> #include <vector> using namespace std; #include <algorithm> #include <bits/stdc++.h> #define ll long long int #define read(a) \ long long int a; \ cin >> a; #define readstr(s) \ string s; \ cin >> s; #define readarr(a, l) \ long long int a[l] = {0}; \ for (ll i = 0; i < l; i++) \ cin >> a[i]; #define loop(i, a, b) for (ll i = a; i < b; i++) #define rloop(i, a, b) for (ll i = a; i > b; i--) #define ff first #define ss second #define readmtrx(i, j, a, b) \ ll arr[a][b] = {0}; \ for (ll i = 0; i < a; i++) \ for (ll j = 0; j < b; j++) \ cin >> arr[i][j]; #define v(pi) vector<ll> pi #define vp(pi) vector<pair<ll, ll>> pi #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb(p) push_back(p) #define mp make_pair #include <cmath> #include <map> #include <string> #define mi(lol) map<ll, ll> lol #define fsort(vec) sort(vec.begin(), vec.end()) #define rsort(vec) sort(vec.begin(), vec.end(), compare) #define inf ll inf = INT_MAX // sorting according to the second element vector bool compare(pair<ll, ll> p, pair<ll, ll> q) { return p.second < q.second; } // example:- // sort(vec.begin(),vec.end(),compare); int main() { fast; // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif read(a) read(b) ll m = a * (a - 1) / 2; ll n = b * (b - 1) / 2; cout << m + n << endl; return 0; }
replace
64
68
64
68
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int m; cin >> n; cin >> m; int res; res = (n * (n - 1)) / (m * (m - 1)); cout << res << '\n'; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main(void) { int n, m; cin >> n >> m; cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl; return 0; }
replace
2
10
2
9
-8
p02729
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define speedrap \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int be(int a, int b, int mod) { if (b == 0) return 1; if (b % 2 == 1) return (a * be(a, b - 1, mod)) % mod; else return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod; } const int mod = 998244353; #define PI 3.1415926535 #define pf push_front #define pb push_back #define bitcount __builtin_popcount #define sc(a) scanf("%d", &a); #define sz(s) (int)s.size() #define eb emplace_back #define pf push_front const int siz = 2 * (1e6 + 1); const int logi = 21; const double epsilon = 1e-6; int fact[siz]; int ifact[siz]; int bit[siz]; bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); } signed main() { #ifndef ONLINE_JUDGE2 freopen("in.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif speedrap int n, m; cin >> n >> m; int sum = n * (n - 1) + m * (m - 1); sum /= 2; cout << sum << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long #define speedrap \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int be(int a, int b, int mod) { if (b == 0) return 1; if (b % 2 == 1) return (a * be(a, b - 1, mod)) % mod; else return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod; } const int mod = 998244353; #define PI 3.1415926535 #define pf push_front #define pb push_back #define bitcount __builtin_popcount #define sc(a) scanf("%d", &a); #define sz(s) (int)s.size() #define eb emplace_back #define pf push_front const int siz = 2 * (1e6 + 1); const int logi = 21; const double epsilon = 1e-6; int fact[siz]; int ifact[siz]; int bit[siz]; bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); } signed main() { // #ifndef ONLINE_JUDGE2 // freopen("in.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif speedrap int n, m; cin >> n >> m; int sum = n * (n - 1) + m * (m - 1); sum /= 2; cout << sum << "\n"; }
replace
33
38
33
37
0
p02729
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; vector<int> data(n + m); if (n == 0 & m == 0) { cout << "0" << endl; return 0; } for (int i = 0; i < n + 1; i++) { data.at(i) = (i + 1) * 2; } int index = 0; for (int i = n; i < n + m; i++) { data.at(i) = index * 2 + 1; } int counter = 0; rep(i, n + m) { for (int j = i; j < n + m; j++) { if (i != j & (data.at(i) + data.at(j)) % 2 == 0) counter++; } // cout << data.at(i) << endl; } cout << counter << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using P = pair<int, int>; int main() { int n, m; cin >> n >> m; vector<int> data(n + m); if (n == 0 & m == 0) { cout << "0" << endl; return 0; } for (int i = 0; i < n; i++) { data.at(i) = (i + 1) * 2; } int index = 0; for (int i = n; i < n + m; i++) { data.at(i) = index * 2 + 1; } int counter = 0; rep(i, n + m) { for (int j = i; j < n + m; j++) { if (i != j & (data.at(i) + data.at(j)) % 2 == 0) counter++; } // cout << data.at(i) << endl; } cout << counter << endl; }
replace
16
17
16
17
0
p02729
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios::sync_with_stdio(NULL); \ cin.tie(NULL) #define mod 1000000007 #define endl "\n" #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define ALL(v) v.begin(), v.end() #define ll long long typedef vector<ll> vecll; typedef vector<int> veci; typedef vector<char> vecc; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; #define pb push_back #define mp make_pair #define time 1.0 * clock() / CLOCKS_PER_SEC int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); cout << "TIME ESCAPED: " << time << endl; #endif // test{} ll m, n; cin >> m >> n; cout << ((m * (m - 1)) / 2) + ((n * (n - 1)) / 2); return 0; }
#include "bits/stdc++.h" using namespace std; #define test \ int t; \ cin >> t; \ while (t--) #define fast \ ios::sync_with_stdio(NULL); \ cin.tie(NULL) #define mod 1000000007 #define endl "\n" #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define ALL(v) v.begin(), v.end() #define ll long long typedef vector<ll> vecll; typedef vector<int> veci; typedef vector<char> vecc; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; #define pb push_back #define mp make_pair #define time 1.0 * clock() / CLOCKS_PER_SEC int main() { fast; // test{} ll m, n; cin >> m >> n; cout << ((m * (m - 1)) / 2) + ((n * (n - 1)) / 2); return 0; }
delete
28
34
28
28
0
p02729
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string n; string m; cin >> n >> m; int iN = atoi(n.c_str()); int iM = atoi(m.c_str()); int retVal = 0; // 偶数から2個とる場合の数 if (iN > 1) { retVal += iN * (iN - 1) / 2; } // 奇数から2個とる場合の数 if (iM > 1) { retVal += iM * (iM - 1) / 2; } return retVal; }
#include <iostream> #include <string> using namespace std; int main() { string n; string m; cin >> n >> m; int iN = atoi(n.c_str()); int iM = atoi(m.c_str()); int retVal = 0; // 偶数から2個とる場合の数 if (iN > 1) { retVal += iN * (iN - 1) / 2; } // 奇数から2個とる場合の数 if (iM > 1) { retVal += iM * (iM - 1) / 2; } cout << retVal << endl; return 0; }
replace
24
25
24
27
1
p02729
C++
Time Limit Exceeded
#include <iostream> using namespace std; long long fun(long long a) { if (a == 1) return 1; return a + fun(a - 1); } int main() { long long n, m; cin >> n >> m; cout << fun(n - 1) + fun(m - 1); return 0; }
#include <iostream> using namespace std; long long fun(long long a) { return (a + 1) * a / 2; } int main() { long long n, m; cin >> n >> m; cout << fun(n - 1) + fun(m - 1); return 0; }
replace
2
7
2
3
TLE
p02729
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <vector> using namespace std; long long int f(int num) { if (num <= 1) { return 1; } else { return (num * f(num - 1)); } } int combine(int n, int m) { return f(n) / (2 * f(n - 2)); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n = 0, m = 0; cin >> n >> m; // cout << combine(13,2)<<endl; if (n <= 1 || m <= 1) { if (n <= 1 && m <= 1) cout << "0"; else if (n <= 1) { cout << combine(m, 2); } else if (m <= 1) { cout << combine(n, 2); } } else { // cout <<"nnn="<<n<<"m="<<m<<endl; // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl; cout << combine(n, 2) + combine(m, 2); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cstdio> #include <iostream> #include <vector> using namespace std; long long int f(int num) { if (num <= 1) { return 1; } else { return (num * f(num - 1)); } } int combine(int n, int m) { return (n * (n - 1)) / 2; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n = 0, m = 0; cin >> n >> m; // cout << combine(13,2)<<endl; if (n <= 1 || m <= 1) { if (n <= 1 && m <= 1) cout << "0"; else if (n <= 1) { cout << combine(m, 2); } else if (m <= 1) { cout << combine(n, 2); } } else { // cout <<"nnn="<<n<<"m="<<m<<endl; // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl; cout << combine(n, 2) + combine(m, 2); } return 0; }
replace
17
18
17
18
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } int lcm(int a, int b) { return a / gcm(a, b) * b; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } signed main() { string s; cin >> s; string t; t = s; rev(t); if (s != t) { cout << "No" << endl; return 0; } string u; for (int i = 0; i < s.size() / 2; i++) { u[i] = s[i]; } rev(u); int a = 1; for (int i = 0; i < s.size() / 2; i++) { if (s[i] != u[i]) { a = 0; break; } } if (a) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; double b = sqrt(a); for (int i = 3; i <= b; i += 2) { if (a % i == 0) { return false; } } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } int lcm(int a, int b) { return a / gcm(a, b) * b; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } signed main() { string s; cin >> s; string t; t = s; rev(t); if (s != t) { cout << "No" << endl; return 0; } V<char> u(s.size() / 2); for (int i = 0; i < s.size() / 2; i++) { u[i] = s[i]; } rev(u); int a = 1; for (int i = 0; i < s.size() / 2; i++) { if (s[i] != u[i]) { a = 0; break; } } if (a) cout << "Yes" << endl; else cout << "No" << endl; }
replace
330
331
330
331
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int n = (S.size() - 1) / 2; bool ans = 1; for (int i = 0; i < (n + 1) / 2; i++) { if (S.at(i) != S.at(n - 1 - i) || S.at(i) != S.at(n + 1 + 1) || S.at(i) != S.at(S.size() - 1 - i)) { ans = 0; break; } } cout << (ans ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int n = (S.size() - 1) / 2; bool ans = 1; for (int i = 0; i < (n + 1) / 2; i++) { if (S.at(i) != S.at(n - 1 - i) || S.at(i) != S.at(n + 1 + i) || S.at(i) != S.at(S.size() - 1 - i)) { ans = 0; break; } } cout << (ans ? "Yes" : "No") << endl; }
replace
9
10
9
10
0
p02730
C++
Runtime Error
#include <algorithm> #include <iostream> #include <list> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, a, b) for (ll i = a; i < b; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef unordered_map<string, ll> u_map; // input void input() {} template <class Head, class... Tail> void input(Head &&a, Tail &&...b) { cin >> a; input(forward<Tail>(b)...); } template <class V> void input(vector<V> &v) { for_each(v.begin(), v.end(), [](auto &i) { input(i); }); } // output template <class V> void output(vector<V> &v) { for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; }); cout << endl; } // math functions ll mpow(ll a, ll n, ll p) { ll x = 1; while (n > 0) { if (n & 1) { x = a * x % p; } a = a * a % p; n >>= 1; } return x; } ll mfact(ll n, ll p) { ll res = 1; for (ll i = 2; i <= n; i++) { res = res * i % p; } return res; } ll mcomb(ll n, ll r, ll p) { if (n == 0 && r == 0) { return 1; } if (n < r || n < 0 || r < 0) { return 0; } ll a = mfact(n, p); ll b = mfact(n - r, p); ll c = mfact(r, p); return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p; } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } bool isPallindrome(string s) { rep(i, 0, s.size() / 2) { if (s[i] != s[s.size() - i - 1]) { return false; } } return true; } int main() { string S; input(S); cout << ((isPallindrome(S) && isPallindrome(S.substr(0, (S.size() - 1) / 2)) && isPallindrome(S.substr((S.size() + 3) / 2 + 1))) ? "Yes" : "No") << endl; return 0; }
#include <algorithm> #include <iostream> #include <list> #include <set> #include <string> #include <unordered_map> #include <vector> #define rep(i, a, b) for (ll i = a; i < b; i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef unordered_map<string, ll> u_map; // input void input() {} template <class Head, class... Tail> void input(Head &&a, Tail &&...b) { cin >> a; input(forward<Tail>(b)...); } template <class V> void input(vector<V> &v) { for_each(v.begin(), v.end(), [](auto &i) { input(i); }); } // output template <class V> void output(vector<V> &v) { for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; }); cout << endl; } // math functions ll mpow(ll a, ll n, ll p) { ll x = 1; while (n > 0) { if (n & 1) { x = a * x % p; } a = a * a % p; n >>= 1; } return x; } ll mfact(ll n, ll p) { ll res = 1; for (ll i = 2; i <= n; i++) { res = res * i % p; } return res; } ll mcomb(ll n, ll r, ll p) { if (n == 0 && r == 0) { return 1; } if (n < r || n < 0 || r < 0) { return 0; } ll a = mfact(n, p); ll b = mfact(n - r, p); ll c = mfact(r, p); return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p; } ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } bool isPallindrome(string s) { rep(i, 0, s.size() / 2) { if (s[i] != s[s.size() - i - 1]) { return false; } } return true; } int main() { string S; input(S); cout << ((isPallindrome(S) && isPallindrome(S.substr(0, (S.size() - 1) / 2)) && isPallindrome(S.substr((S.size() + 3) / 2 - 1))) ? "Yes" : "No") << endl; return 0; }
replace
96
97
96
97
0
p02730
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(k, a, b) for (int k = (a); k < (b); k++) #define FORE(k, a, b) for (int k = (a); k <= (b); k++) #define REP(k, a) for (int k = 0; k < (a); k++) #define ALL(c) (c).begin(), (c).end() #define EXIST(s, e) ((s).find(e) != (s).end()) #define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub)) #define dump(x) cerr << #x << ": " << (x) << endl; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; const int INF = 1000000000; const double EPS = 1e-10; const double PI = acos(-1.0); bool is_palind(string s) { if (s.size() == 1) return true; return (s[0] != s[s.size() - 1]) ? false : is_palind(s.substr(1, s.size() - 2)); } int main(void) { string s; cin >> s; int n = s.size(); cout << ((is_palind(s) && is_palind(s.substr(0, n / 2)) && is_palind(s.substr((n + 3) / 2 - 1, n / 2))) ? "Yes" : "No") << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(k, a, b) for (int k = (a); k < (b); k++) #define FORE(k, a, b) for (int k = (a); k <= (b); k++) #define REP(k, a) for (int k = 0; k < (a); k++) #define ALL(c) (c).begin(), (c).end() #define EXIST(s, e) ((s).find(e) != (s).end()) #define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub)) #define dump(x) cerr << #x << ": " << (x) << endl; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; const int INF = 1000000000; const double EPS = 1e-10; const double PI = acos(-1.0); bool is_palind(string s) { if (s.size() <= 1) return true; return (s[0] != s[s.size() - 1]) ? false : is_palind(s.substr(1, s.size() - 2)); } int main(void) { string s; cin >> s; int n = s.size(); cout << ((is_palind(s) && is_palind(s.substr(0, n / 2)) && is_palind(s.substr((n + 3) / 2 - 1, n / 2))) ? "Yes" : "No") << endl; return 0; }
replace
47
48
47
48
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; int N; int M = 0; cin >> S; N = S.size(); for (int i = 0; i < (N - 1) / 2; i++) { if (S.at(i) != S.at((N + 3) / 2 + i)) { M = 1; } } if (M == 1) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string S; int N; int M = 0; cin >> S; N = S.size(); for (int i = 0; i < (N - 1) / 2; i++) { if (S.at(i) != S.at((N - 1) / 2 + 1 + i)) { M = 1; } } if (M == 1) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
9
10
9
10
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 7) >= this->size() (which is 7)
p02730
Python
Runtime Error
S = input() a = len(S) if S[: (a - 1) / 2] == S[(a + 1) / 2 :]: print("Yes") else: print("No")
S = input() n = len(S) a = S[: int((n - 1) / 2)] b = S[int((n + 1) / 2) :] if a == b: print("Yes") else: print("No")
replace
1
3
1
5
TypeError: slice indices must be integers or None or have an __index__ method
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02730/Python/s829977538.py", line 3, in <module> if S[:(a - 1) / 2] == S[(a + 1) / 2:]: TypeError: slice indices must be integers or None or have an __index__ method
p02730
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, s, N) for (int i = s; i < (N); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; using namespace std; bool judge(string str) { bool a = true; int h = str.length() / 2; if (str.length() == 1) { a = true; //}else if(str.length()%2==0){ // a = false; } else { int k = 1; while (h - k >= 0) { if (str.at(h - k) == str.at(h + k)) { k++; // continue; } else { a = false; break; } } } return a; } int main() { string S; cin >> S; int N = S.length(); string S2 = S.substr(0, (N - 1) / 2); string S3 = S.substr((N + 3) / 2 - 1); if (judge(S) && judge(S2) && judge(S3)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> #define REP(i, s, N) for (int i = s; i < (N); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; using namespace std; bool judge(string str) { string str1 = str; reverse(str.begin(), str.end()); return str == str1; } int main() { string S; cin >> S; int N = S.length(); string S2 = S.substr(0, (N - 1) / 2); string S3 = S.substr((N + 3) / 2 - 1); if (judge(S) && judge(S2) && judge(S3)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
8
28
8
11
0
p02730
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char S[100]; char mae[50] = {}; char ato[50] = {}; char mae_mae[25] = {}; char mae_ato[25] = {}; char ato_mae[25] = {}; char ato_ato[25] = {}; scanf("%s", &S); strncpy(mae, S, (strlen(S) - 1) / 2); for (int i = 0; i < (strlen(S) - 1) / 2; ++i) { ato[i] = S[(strlen(S) - 1 - i)]; } if (strcmp(mae, ato) != 0) { printf("No"); return 0; } if (strlen(mae) % 2 == 1) { strncpy(mae_mae, mae, (strlen(mae) - 1) / 2); strncpy(ato_mae, ato, (strlen(ato) - 1) / 2); for (int i = 0; i < (strlen(mae) - 1) / 2; ++i) { mae_ato[i] = S[(strlen(mae) - 1 - i)]; ato_ato[i] = S[(strlen(mae) - 1 - i)]; } } else { strncpy(mae_mae, mae, strlen(mae) / 2); strncpy(ato_mae, ato, strlen(ato) / 2); for (int i = 0; i < (strlen(mae)) / 2; ++i) { strncpy(mae_ato, mae + strlen(mae) / 2 + 1, strlen(mae)); strncpy(ato_ato, ato + strlen(ato) / 2 + 1, strlen(ato)); } } if (strcmp(mae_mae, mae_ato) != 0 || strcmp(ato_mae, ato_ato) != 0) { printf("No"); return 0; } else { printf("Yes"); return 0; } } int A() { int N, M; int ans; scanf("%d %d", &N, &M); ans = (N - 1) * N / 2 + (M - 1) * M / 2; printf("%d", ans); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char S[100]; char mae[50] = {}; char ato[50] = {}; char mae_mae[25] = {}; char mae_ato[25] = {}; char ato_mae[25] = {}; char ato_ato[25] = {}; scanf("%s", &S); strncpy(mae, S, (strlen(S) - 1) / 2); for (int i = 0; i < (strlen(S) - 1) / 2; ++i) { ato[i] = S[(strlen(S) - 1 - i)]; } if (strcmp(mae, ato) != 0) { printf("No"); return 0; } if (strlen(mae) % 2 == 1) { strncpy(mae_mae, mae, (strlen(mae) - 1) / 2); strncpy(ato_mae, ato, (strlen(ato) - 1) / 2); for (int i = 0; i < (strlen(mae) - 1) / 2; ++i) { mae_ato[i] = S[(strlen(mae) - 1 - i)]; ato_ato[i] = S[(strlen(mae) - 1 - i)]; } } else { strncpy(mae_mae, mae, strlen(mae) / 2); strncpy(ato_mae, ato, strlen(ato) / 2); for (int i = 0; i < (strlen(mae)) / 2; ++i) { mae_ato[i] = S[(strlen(mae) - 1 - i)]; ato_ato[i] = S[(strlen(mae) - 1 - i)]; } } if (strcmp(mae_mae, mae_ato) != 0 || strcmp(ato_mae, ato_ato) != 0) { printf("No"); return 0; } else { printf("Yes"); return 0; } } int A() { int N, M; int ans; scanf("%d %d", &N, &M); ans = (N - 1) * N / 2 + (M - 1) * M / 2; printf("%d", ans); return 0; }
replace
36
38
36
38
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) const int INF = 2147483647; // int max const int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s; cin >> s; string re_s = s; reverse(re_s.begin(), re_s.end()); if (s == re_s) { int n = s.length(); string b = s.substr(0, (n - 1) / 2); string re_b = b; reverse(re_b.begin(), re_b.end()); if (b == re_b) { string f = s.substr((n + 3) / 2 + 1); string re_f = f; reverse(re_f.begin(), re_f.end()); if (f == re_f) { cout << "Yes\n"; return 0; } } } cout << "No\n"; return 0; } /* やっほい!        やほほい!     +    *     ∧∧  . ∧∞∧ * * ヽ(=´ω`)人(´ω`*)ノ  .~( O x.) (   O)~ + 。*   ∪    ∪ */
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) const int INF = 2147483647; // int max const int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; int main() { string s; cin >> s; int n = s.length(); string r = ""; for (int i = n - 1; i >= 0; i--) r += s[i]; if (s == r) { string f = ""; for (int i = (n - 1) / 2 - 1; i >= 0; i--) f += s[i]; if (f == s.substr(0, (n - 1) / 2)) { string b = ""; for (int i = n - 1; i >= (n + 3) / 2 - 1; i--) b += s[i]; string c = s.substr((n + 3) / 2 - 1); if (b == c) { cout << "Yes\n"; return 0; } } } cout << "No\n"; return 0; } /* やっほい!        やほほい!     +    *     ∧∧  . ∧∞∧ * * ヽ(=´ω`)人(´ω`*)ノ  .~( O x.) (   O)~ + 。*   ∪    ∪ */
replace
11
23
11
25
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mod (int)1000000007 #define MOD (int)10000000007 #define X 1001100011100001111ll #define M 26388279066623ll #define all(a) a.begin(), a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for0e(i, n) for (int i = 0; i <= n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define bloop(i, a, b) for (int i = a; i >= b; i--) #define tc(t) \ int t; \ cin >> t; \ while (t--) #define ll long long #define pb emplace_back #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define in(x) scanf("%d", &x) #define rr return 0 #define prec(n) fixed << setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define F first #define S second #define pi pair<int, int> #define ppi pair<pair<int, int>, int> #define vii vector<pi> const int MAXN = (int)((1e5) + 100); int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int cbrt(int x) { int lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { int mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi = mid; } if (hi * hi * hi <= x) return hi; else return lo; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const int N = (int)(1e6 + 5); bool is_palindrome(string s) { string t(s.rbegin(), s.rend()); return s == t; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fio; string s; cin >> s; const int n = s.size(); if (is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) && is_palindrome(s.substr((n + 1) / 2))) { cout << "Yes" << endl; } else cout << "No" << endl; rr; }
#include <bits/stdc++.h> using namespace std; #define mod (int)1000000007 #define MOD (int)10000000007 #define X 1001100011100001111ll #define M 26388279066623ll #define all(a) a.begin(), a.end() #define for0(i, n) for (int i = 0; i < n; i++) #define for0e(i, n) for (int i = 0; i <= n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define bloop(i, a, b) for (int i = a; i >= b; i--) #define tc(t) \ int t; \ cin >> t; \ while (t--) #define ll long long #define pb emplace_back #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define in(x) scanf("%d", &x) #define rr return 0 #define prec(n) fixed << setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define F first #define S second #define pi pair<int, int> #define ppi pair<pair<int, int>, int> #define vii vector<pi> const int MAXN = (int)((1e5) + 100); int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a < b) return a; else return b; } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int cbrt(int x) { int lo = 1, hi = min(2000000ll, x); while (hi - lo > 1) { int mid = (lo + hi) / 2; if (mid * mid * mid < x) { lo = mid; } else hi = mid; } if (hi * hi * hi <= x) return hi; else return lo; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const int N = (int)(1e6 + 5); bool is_palindrome(string s) { string t(s.rbegin(), s.rend()); return s == t; } signed main() { fio; string s; cin >> s; const int n = s.size(); if (is_palindrome(s) && is_palindrome(s.substr(0, (n - 1) / 2)) && is_palindrome(s.substr((n + 1) / 2))) { cout << "Yes" << endl; } else cout << "No" << endl; rr; }
delete
73
77
73
73
0
p02730
C++
Runtime Error
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //* vamsicool007 You are never wrong to do the right thing vamsicool007 * //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #include <bits/stdc++.h> using namespace std; #define flash \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define F first #define S second #define pb push_back #define mp make_pair #define mt make_tuple #define endl "\n" #define int long long typedef long long ll; typedef long double ld; const int mod = 1000000007; const int N = 200005; vector<int> vis(N); vector<vector<int>> adj(N); void dfs(int v) { vis[v] = 1; for (auto i : adj[v]) { if (!vis[i]) { dfs(i); } } return; } bool isPrime(ll n) { if (n < 2) return false; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } ll power(ll x, ll y) { ll res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res % mod; } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } ll max(ll a, ll b) { ll ans = a > b ? a : b; return ans; } ll min(ll a, ll b) { ll ans = a < b ? a : b; return ans; } int root(int a[], int i) { while (a[i] != i) { a[i] = a[a[i]]; i = a[i]; } return i; } void unionn(int a[], int i, int j) { int root_i = root(a, i); int root_j = root(a, j); a[root_i] = root_j; return; } void fun() { #ifndef ONLINE_JUDGE freopen("infile.txt", "r", stdin); freopen("oufile.txt", "w", stdout); #endif } signed main() { flash; fun(); int t = 1; // cin>>t; while (t--) { string s; cin >> s; int n = s.size(); int f = 0; for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) { f = 1; break; } } if (!f) { int m = (n - 1) / 2; int f1 = 0; for (int i = 0; i < (n - 1) / 4; i++) { if (s[i] != s[m - 1 - i]) { f1 = 1; break; } } int j = (n + 3) / 2; int k = (2 * n + 3) / 4; int f2 = 0; for (int i = j; i < k; i++) { if (s[i] != s[k - i - 1]) { f2 = 1; break; } } if (!f1 && !f2) cout << "Yes"; else cout << "No"; } else cout << "No"; } return 0; }
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //* vamsicool007 You are never wrong to do the right thing vamsicool007 * //* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #include <bits/stdc++.h> using namespace std; #define flash \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define F first #define S second #define pb push_back #define mp make_pair #define mt make_tuple #define endl "\n" #define int long long typedef long long ll; typedef long double ld; const int mod = 1000000007; const int N = 200005; vector<int> vis(N); vector<vector<int>> adj(N); void dfs(int v) { vis[v] = 1; for (auto i : adj[v]) { if (!vis[i]) { dfs(i); } } return; } bool isPrime(ll n) { if (n < 2) return false; for (ll i = 2; i * i <= n; ++i) { if (n % i == 0) { return false; } } return true; } ll factorial(ll n) { return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); } ll power(ll x, ll y) { ll res = 1; x = x; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res % mod; } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a, ll b) { return (a / gcd(a, b) * b); } ll max(ll a, ll b) { ll ans = a > b ? a : b; return ans; } ll min(ll a, ll b) { ll ans = a < b ? a : b; return ans; } int root(int a[], int i) { while (a[i] != i) { a[i] = a[a[i]]; i = a[i]; } return i; } void unionn(int a[], int i, int j) { int root_i = root(a, i); int root_j = root(a, j); a[root_i] = root_j; return; } void fun() { #ifndef ONLINE_JUDGE freopen("infile.txt", "r", stdin); freopen("oufile.txt", "w", stdout); #endif } signed main() { flash; // fun(); int t = 1; // cin>>t; while (t--) { string s; cin >> s; int n = s.size(); int f = 0; for (int i = 0; i < n / 2; i++) { if (s[i] != s[n - i - 1]) { f = 1; break; } } if (!f) { int m = (n - 1) / 2; int f1 = 0; for (int i = 0; i < (n - 1) / 4; i++) { if (s[i] != s[m - 1 - i]) { f1 = 1; break; } } int j = (n + 3) / 2; int k = (2 * n + 3) / 4; int f2 = 0; for (int i = j; i < k; i++) { if (s[i] != s[k - i - 1]) { f2 = 1; break; } } if (!f1 && !f2) cout << "Yes"; else cout << "No"; } else cout << "No"; } return 0; }
replace
89
90
89
90
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; string S; bool check(string str) { int len = str.length(); int af = len / 2; for (int i = 0; i < af; i++) { if (str[i] != str[len - i - 1]) { return false; } } return true; } void Main() { int len = S.length(); int af = len / 2; if (check(S) && check(S.substr(0, af))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return; } int main() { cin >> S; Main(); return 1; }
#include <bits/stdc++.h> using namespace std; string S; bool check(string str) { int len = str.length(); int af = len / 2; for (int i = 0; i < af; i++) { if (str[i] != str[len - i - 1]) { return false; } } return true; } void Main() { int len = S.length(); int af = len / 2; if (check(S) && check(S.substr(0, af))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return; } int main() { cin >> S; Main(); return 0; }
replace
31
32
31
32
1
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool kaibun(string s) { int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); if (kaibun(s) && kaibun(s.substr(0, (n - 1) / 2)) && kaibun(s.substr(((n + 3) / 2) + 1))) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; bool kaibun(string s) { int n = s.length(); for (int i = 0; i < n; i++) { if (s[i] != s[n - i - 1]) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); if (kaibun(s) && kaibun(s.substr(0, (n - 1) / 2)) && kaibun(s.substr(((n + 3) / 2) - 1))) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
18
19
18
19
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; bool check(string s) { bool res = true; int n = s.size(); for (int i = 0; i < n / 2; ++i) { if (s[i] != s[n - 1 - i]) res = false; } return res; } int main() { string s; cin >> s; int n = s.size(); string ans = "No"; if (check(s) && check(s.substr(0, n / 2)) && check(s.substr((n + 3) / 2 + 1))) ans = "Yes"; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; bool check(string s) { bool res = true; int n = s.size(); for (int i = 0; i < n / 2; ++i) { if (s[i] != s[n - 1 - i]) res = false; } return res; } int main() { string s; cin >> s; int n = s.size(); string ans = "No"; if (check(s) && check(s.substr(0, n / 2)) && check(s.substr((n + 3) / 2 - 1))) ans = "Yes"; cout << ans << endl; }
replace
19
20
19
20
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; bool round_word(string s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s.at(i) != s.at(n - 1 - i)) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); if (round_word(s) && round_word(s.substr(0, (n - 1) / 2)) && round_word(s.substr((n + 3) / 2 + 1))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; bool round_word(string s) { int n = s.length(); for (int i = 0; i < n / 2; i++) { if (s.at(i) != s.at(n - 1 - i)) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); if (round_word(s) && round_word(s.substr(0, (n - 1) / 2)) && round_word(s.substr((n + 3) / 2 - 1))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
19
20
19
20
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); bool judge = true; for (int i = 0; i < (n - 1) / 2; i++) { if (s.at(i) != s.at(n - 1 - i)) { judge = false; break; } } if (judge) { for (int i = 0; i < (n - 1) / 4; i++) { if (s.at(i) != s.at((n - 1) / 2 - 1 - n)) { judge = false; break; } } } if (judge) { int j = 0; for (int i = (n + 3) / 2 - 1; i < n; i++) { if (s.at(i) != s.at(n - 1 - j)) { judge = false; break; } j++; } } if (judge) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); bool judge = true; for (int i = 0; i < (n - 1) / 2; i++) { if (s.at(i) != s.at(n - 1 - i)) { judge = false; break; } } if (judge) { for (int i = 0; i < n / 2; i++) { if (s.at(i) != s.at((n - 1) / 2 - 1 - i)) { judge = false; break; } } } if (judge) { int j = 0; for (int i = (n + 3) / 2 - 1; i < n; i++) { if (s.at(i) != s.at(n - 1 - j)) { judge = false; break; } j++; } } if (judge) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
17
19
17
19
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 18446744073709551611) >= this->size() (which is 7)
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool kaibun(string S, int A, int B) { // Sの文字数は3以上の奇数 // SのA文字目からB文字目までが回文かどうかを判定する関数 int i = A - 1; int j = B - 1; while (i != j) { if (S.at(i) != S.at(j)) return false; i += 1; j += -1; } return true; } int main() { string S; cin >> S; int N = S.size(); if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N)) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; bool kaibun(string S, int A, int B) { // Sの文字数は3以上の奇数 // SのA文字目からB文字目までが回文かどうかを判定する関数 int i = A - 1; int j = B - 1; while (i <= j) { if (S.at(i) != S.at(j)) return false; i += 1; j += -1; } return true; } int main() { string S; cin >> S; int N = S.size(); if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N)) cout << "Yes" << endl; else cout << "No" << endl; }
replace
8
9
8
9
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } bool isPalindrome(string s) { int si = 0, ei = s.size() - 1; while (si != ei) { if (s.at(si) != s.at(ei)) return false; si++; ei--; } return true; } int main() { string S; cin >> S; int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2; string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size()); cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } bool isPalindrome(string s) { string es = s; reverse(all(es)); return s == es; } int main() { string S; cin >> S; int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2; string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size()); cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes" : "No") << endl; }
replace
21
29
21
24
0
p02730
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define N 100005 #define mod 998244353 #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define prec(n) fixed << setprecision(n) #define mii unordered_map<int, int> #define mll unordered_map<ll, ll> #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define mp make_pair #define pp pop_back #define vii vector<int> #define vll vector<ll> #define vpp vector<pii> #define all(c) c.begin(), c.end() #define tr(it, c) for (it = c.begin(); it != c.end(); it++) int inf = INT_MAX; ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; } // for negative integer ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e % 2) ans = (ans * b) % MOD; b = (b * b) % MOD; e /= 2; } return ans; } ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } int is_pallindrome(string str, int i, int j) { while (i < j) { if (str[i] != str[j]) return 0; } return 1; } int main() { boost; string str; cin >> str; int n = str.size(); int i = is_pallindrome(str, 0, str.size() - 1); int j = is_pallindrome(str, 0, (n - 1) / 2 - 1); int k = is_pallindrome(str, (n + 3) / 2 - 1, n - 1); if (i & j & k) { cout << "Yes"; } else { cout << "No"; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define N 100005 #define mod 998244353 #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define prec(n) fixed << setprecision(n) #define mii unordered_map<int, int> #define mll unordered_map<ll, ll> #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define pb push_back #define mp make_pair #define pp pop_back #define vii vector<int> #define vll vector<ll> #define vpp vector<pii> #define all(c) c.begin(), c.end() #define tr(it, c) for (it = c.begin(); it != c.end(); it++) int inf = INT_MAX; ll modulo(ll num, ll MOD = mod) { return ((num % MOD) + MOD) % MOD; } // for negative integer ll power(ll b, ll e, ll MOD = mod) { ll ans = 1; while (e) { if (e % 2) ans = (ans * b) % MOD; b = (b * b) % MOD; e /= 2; } return ans; } ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); } ll gcd(ll a, ll b) { return ((b == 0) ? a : gcd(b, a % b)); } int is_pallindrome(string str, int i, int j) { while (i < j) { if (str[i] != str[j]) return 0; i++, j--; } return 1; } int main() { boost; string str; cin >> str; int n = str.size(); int i = is_pallindrome(str, 0, str.size() - 1); int j = is_pallindrome(str, 0, (n - 1) / 2 - 1); int k = is_pallindrome(str, (n + 3) / 2 - 1, n - 1); if (i & j & k) { cout << "Yes"; } else { cout << "No"; } }
insert
48
48
48
49
TLE
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); string ans = "Yes"; for (int i = 0; i <= (N - 3) / 4; i++) { if (S.at(i) != S.at(N - i) || S.at(i) != S.at((N - 3) / 2)) { ans = "No"; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int N = S.size(); string ans = "Yes"; for (int i = 0; i <= (N - 3) / 2; i++) { if (S.at(i) != S.at(N - i - 1) || S.at(i) != S.at((N - 3) / 2 - i)) { ans = "No"; break; } } cout << ans << endl; return 0; }
replace
7
9
7
9
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 7) >= this->size() (which is 7)
p02730
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define int long long int signed main() { string s; int s_center = (s.length() + 1) / 2; string mae = s.substr(s_center - 1); string usiro = s.substr(s_center + 1, (s.length() / 2)); if (mae == usiro) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define int long long int signed main() { string s; cin >> s; int s_center = ((s.length() + 1) / 2) - 1; string mae = s.substr(0, s_center); string usiro = s.substr(s_center + 1); if (mae == usiro) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
9
12
9
13
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 0)
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) \ SORT(var); \ REVERSE(var) #define OPTIMIZE_STDIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.precision(10); \ cout << fixed #define endl '\n' const int INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; struct mint { ll x; mint() : x(0) {} mint(ll x) : x((x % MOD + MOD) % MOD) {} mint &operator+=(const mint &r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; } mint &operator-=(const mint &r) { if ((x -= r.x) < 0) { x += MOD; } return *this; } mint &operator*=(const mint &r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; } mint &operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; } mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x -= MOD; } return ret; } mint &operator--() { if ((--x) < 0) { x += MOD; } return *this; } mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; } mint operator+(const mint &r) { mint ret; return ret = x + r.x; } mint operator-(const mint &r) { mint ret; return ret = x - r.x; } mint operator*(const mint &r) { mint ret; return ret = x * r.x; } mint operator-() { return mint() - *this; } bool operator<(const mint &a) { return x < a.x; } bool operator>(const mint &a) { return x > a.x; } bool operator<=(const mint &a) { return x <= a.x; } bool operator>=(const mint &a) { return x >= a.x; } bool operator==(const mint &a) { return x == a.x; } bool operator!=(const mint &a) { return x != a.x; } }; ostream &operator<<(ostream &os, const mint &r) { os << r.x; return os; } ostream &operator>>(ostream &os, const mint &r) { os >> r.x; return os; } bool is_ok(string s) { int f = 1; REP(i, s.size() / 2) { if (s[i] != s[s.size() - 1 - i]) f = 0; } if (f == 1) return true; else return false; } void solve(istream &cin, ostream &cout) { string s; cin >> s; int n = s.size(); string a, b; a = s.substr(0, (n - 1) / 2); b = s.substr((n + 3) / 2 - 1, (n - 1) / 2); if (is_ok(s) && is_ok(a) && is_ok(b)) cout << "Yes" << endl; else cout << "No" << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); } #endif
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) \ SORT(var); \ REVERSE(var) #define OPTIMIZE_STDIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.precision(10); \ cout << fixed #define endl '\n' const int INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; struct mint { ll x; mint() : x(0) {} mint(ll x) : x((x % MOD + MOD) % MOD) {} mint &operator+=(const mint &r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; } mint &operator-=(const mint &r) { if ((x -= r.x) < 0) { x += MOD; } return *this; } mint &operator*=(const mint &r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; } mint &operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; } mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x -= MOD; } return ret; } mint &operator--() { if ((--x) < 0) { x += MOD; } return *this; } mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; } mint operator+(const mint &r) { mint ret; return ret = x + r.x; } mint operator-(const mint &r) { mint ret; return ret = x - r.x; } mint operator*(const mint &r) { mint ret; return ret = x * r.x; } mint operator-() { return mint() - *this; } bool operator<(const mint &a) { return x < a.x; } bool operator>(const mint &a) { return x > a.x; } bool operator<=(const mint &a) { return x <= a.x; } bool operator>=(const mint &a) { return x >= a.x; } bool operator==(const mint &a) { return x == a.x; } bool operator!=(const mint &a) { return x != a.x; } }; ostream &operator<<(ostream &os, const mint &r) { os << r.x; return os; } ostream &operator>>(ostream &os, const mint &r) { os >> r.x; return os; } bool is_ok(string s) { int f = 1; int l; if (s.size() % 2 == 0) l = s.size() / 2; else l = (s.size() - 1) / 2; REP(i, l) { if (s[i] != s[s.size() - 1 - i]) f = 0; } if (f == 1) return true; else return false; } void solve(istream &cin, ostream &cout) { string s; cin >> s; int n = s.size(); string a, b; a = s.substr(0, (n - 1) / 2); b = s.substr((n + 3) / 2 - 1, (n - 1) / 2); if (is_ok(s) && is_ok(a) && is_ok(b)) cout << "Yes" << endl; else cout << "No" << endl; } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); } #endif
replace
102
103
102
108
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool judge(string &s) { for (int i = 0, j = s.size() - 1; i != j; ++i, --j) { if (s.at(i) != s.at(j)) return true; } return false; } int main() { cin.tie(0), ios::sync_with_stdio(false); string s; cin >> s; bool yes = true; int n = s.size(), n2; if (judge(s)) yes = false; string s2 = s.substr(0, (n - 1) / 2); n2 = s2.size(); if (yes == true && judge(s2)) yes = false; s2 = s.substr((n + 3) / 2 - 1, n2); if (yes == true && judge(s2)) yes = false; if (yes) cout << "Yes\n"s; else cout << "No\n"s; }
#include <bits/stdc++.h> using namespace std; bool judge(string &s) { string s2 = s; reverse(s2.begin(), s2.end()); return s != s2; } int main() { cin.tie(0), ios::sync_with_stdio(false); string s; cin >> s; bool yes = true; int n = s.size(), n2; if (judge(s)) yes = false; string s2 = s.substr(0, (n - 1) / 2); n2 = s2.size(); if (yes == true && judge(s2)) yes = false; s2 = s.substr((n + 3) / 2 - 1, n2); if (yes == true && judge(s2)) yes = false; if (yes) cout << "Yes\n"s; else cout << "No\n"s; }
replace
4
9
4
7
0
p02730
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vl>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpii = vector<pll>; int main() { string S; cin >> S; ll N = S.size(); ll left = 0, right = N - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } } left = 0; right = (N - 1) / 2 - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } left++; right--; } left = (N + 3) / 2 - 1; right = N - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } left++; right--; } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for (int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vl>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpii = vector<pll>; int main() { string S; cin >> S; ll N = S.size(); ll left = 0, right = N - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } left++; right--; } left = 0; right = (N - 1) / 2 - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } left++; right--; } left = (N + 3) / 2 - 1; right = N - 1; while (left < right) { if (S[left] != S[right]) { cout << "No" << endl; return 0; } left++; right--; } cout << "Yes" << endl; return 0; }
insert
24
24
24
26
TLE
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, n) for (int i = (a); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define FORD(i, a, n) for (int i = (a); i >= (n); i--) #define REPD(i, n) FOR(i, n, 0) #define ALL(o) (o).begin(), (o).end() template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; template <class T> using PQ = priority_queue<T>; template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>; const ll MOD = 1000000007; bool f(string s) { string ss = s; reverse(ALL(ss)); if (s == ss) { return true; } return false; } int main() { string s; cin >> s; int n = s.size(); if (f(s) && f(s.substr(0, n / 2)) && f(s.substr((n + 3) / 2 + 1, (n - (n + 3) / 2 + 1)))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, n) for (int i = (a); i < (n); i++) #define REP(i, n) FOR(i, 0, n) #define FORD(i, a, n) for (int i = (a); i >= (n); i--) #define REPD(i, n) FOR(i, n, 0) #define ALL(o) (o).begin(), (o).end() template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; template <class T> using PQ = priority_queue<T>; template <class T> using PQR = priority_queue<T, vector<T>, greater<T>>; const ll MOD = 1000000007; bool f(string s) { string ss = s; reverse(ALL(ss)); if (s == ss) { return true; } return false; } int main() { string s; cin >> s; int n = s.size(); if (f(s) && f(s.substr(0, n / 2)) && f(s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1))) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
replace
34
35
34
35
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { string s; cin >> s; n = s.length(); string t1, t2; flag = 0; fo(i, (n - 1) / 2) t1.pb(s[i]); repa(i, (n + 3) / 2 - 1, n) t2.pb(s[i]); // cout << t1 << endl << t2; fo(i, n) { if (s[i] != s[n - 1 - i]) flag = 1; } fo(i, t1.length()) { if (t1[i] != t1[t1.length() - 1 - i]) flag = 1; } fo(i, t2.length()) { if (t2[i] != t2[t2.length() - 1 - i]) flag = 1; } flag ? cout << "No" : cout << "Yes"; } return 0; }
#include <bits/stdc++.h> #define ll long long int #define double /*long*/ double #define endl '\n' #define vll vector<ll> #define pll pair<ll, ll> #define vpll vector<pll> #define vppll vector<pair<pll, pll>> #define mp make_pair #define pb push_back #define mapll map<ll, ll> #define fir first #define sec second #define _cin \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define fo(i, b) for (i = 0; i < b; i++) #define repa(i, a, b) for (i = a; i < b; i++) #define repb(i, a, b) for (i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() #define s(v) v.size() const long long int MAX = (ll)(1e18 + 1); const long long int MIN = (ll)(-1e18 - 1); const long long int mod = (ll)(1e9 + 7); using namespace std; ll max(ll a, ll b, ll c) { return max(max(a, b), c); } ll min(ll a, ll b, ll c) { return min(min(a, b), c); } ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } ll power(ll a, ll n) { ll p = 1; while (n > 0) { if (n % 2) { p = p * a; } n >>= 1; a *= a; } return p; } ll power_mod(ll a, ll n, ll mod_) { ll p = 1; while (n) { if (n % 2) { p = (p * a) % mod_; } n /= 2; a = (a * a) % mod_; } return p % mod_; } /*Code Begins*/ int main() { _cin; // cout << setprecision(15); ll mn = MAX, mx = MIN; ll n, t, m, k, i, j, sum = 0, prev, flag = 0, cnt = 0; ll x = 0, y = 0, fx, diff, tot = 0, l, r; int TC = 1; // cin >> TC; while (TC--) { string s; cin >> s; n = s.length(); string t1, t2; flag = 0; fo(i, (n - 1) / 2) t1.pb(s[i]); repa(i, (n + 3) / 2 - 1, n) t2.pb(s[i]); // cout << t1 << endl << t2; fo(i, n) { if (s[i] != s[n - 1 - i]) flag = 1; } fo(i, t1.length()) { if (t1[i] != t1[t1.length() - 1 - i]) flag = 1; } fo(i, t2.length()) { if (t2[i] != t2[t2.length() - 1 - i]) flag = 1; } flag ? cout << "No" : cout << "Yes"; } return 0; }
delete
55
60
55
55
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; (i) < (b); ++(i)) #define RFOR(i, a, b) for (ll i = a; (i) >= (b); --(i)) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, n, 0) #define ALL(v) v.begin(), v.end() #define UNIQ(v) \ sort(ALL(v)); \ v.erase(unique(ALL(v)), v.end()) #define BIT(n) (1LL << (n)) #define DEBUG(a) cerr << #a << " = " << a << endl const int inf = 1001001001; const int mod = (int)1e9 + 7; // const ll inf = 1e15; // const ll mod = 1e9+7; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int main() { string s; cin >> s; string rs = s; int l = s.size(); reverse(ALL(rs)); string kai = s.substr(0, (l - 1) / 2); while (kai.size() != 1) { if (kai.back() != kai.front()) { cout << "No" << endl; return 0; } kai.pop_back(); kai.erase(0, 1); } if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (ll i = a; (i) < (b); ++(i)) #define RFOR(i, a, b) for (ll i = a; (i) >= (b); --(i)) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, n, 0) #define ALL(v) v.begin(), v.end() #define UNIQ(v) \ sort(ALL(v)); \ v.erase(unique(ALL(v)), v.end()) #define BIT(n) (1LL << (n)) #define DEBUG(a) cerr << #a << " = " << a << endl const int inf = 1001001001; const int mod = (int)1e9 + 7; // const ll inf = 1e15; // const ll mod = 1e9+7; int dy[] = {0, 0, 1, -1}; int dx[] = {1, -1, 0, 0}; int main() { string s; cin >> s; string rs = s; int l = s.size(); reverse(ALL(rs)); string kai = s.substr(0, (l - 1) / 2); while (kai.size() > 1) { if (kai.back() != kai.front()) { cout << "No" << endl; return 0; } kai.pop_back(); kai.erase(0, 1); } if (s.substr(0, (l - 1) / 2) == rs.substr(0, (l - 1) / 2)) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
31
32
31
32
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define clean(x, y) memset(x, y, sizeof(x)); #define pb push_back #define F first #define S second #define LB lower_bound #define UB upper_bound #define ALL(v) v.begin(), v.end() #define PI acos(-1.0) #define EPS 1e-9 #define INF (1 << 30) #define MOD 1000000007 #define MAX 100005 #define endl "\n" #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define dbg(x) cout << (#x) << "=" << (x) << ":\n" #define CS(i) cout << "Case " << i << ": " #define tin \ ll T; \ cin >> T; \ while (T--) typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; bool isPalindrome(string s) { string rev = s; reverse(ALL(rev)); return rev == s; } int main() { FAST string s; int i, j, x, y, len; cin >> s; len = s.size(); if (len % 2 == 0) { cout << "No\n"; return 0; } if (isPalindrome(s)) { x = (len - 1) / 2; y = (len + 3) / 2 + 1; string s1 = s.substr(0, x); string s2 = s.substr(y); if (isPalindrome(s1) && isPalindrome(s2)) cout << "Yes\n"; else cout << "No\n"; } else { cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define clean(x, y) memset(x, y, sizeof(x)); #define pb push_back #define F first #define S second #define LB lower_bound #define UB upper_bound #define ALL(v) v.begin(), v.end() #define PI acos(-1.0) #define EPS 1e-9 #define INF (1 << 30) #define MOD 1000000007 #define MAX 100005 #define endl "\n" #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define dbg(x) cout << (#x) << "=" << (x) << ":\n" #define CS(i) cout << "Case " << i << ": " #define tin \ ll T; \ cin >> T; \ while (T--) typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; bool isPalindrome(string s) { string rev = s; reverse(ALL(rev)); return rev == s; } int main() { FAST string s; int i, j, x, y, len; cin >> s; len = s.size(); if (len % 2 == 0) { cout << "No\n"; return 0; } if (isPalindrome(s)) { x = (len - 1) / 2; y = (len + 3) / 2 - 1; string s1 = s.substr(0, x); string s2 = s.substr(y); if (isPalindrome(s1) && isPalindrome(s2)) cout << "Yes\n"; else cout << "No\n"; } else { cout << "No\n"; } return 0; }
replace
52
53
52
53
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lli long long int #define st first #define nd second #define mp make_pair #define pb push_back #define INF 1000000007 #define endl "\n" lli n, m; string a, a2, a3; int main() { #ifndef ONLINE_JUDGE freopen("zgir.gir", "r", stdin); freopen("zcik.cik", "w", stdout); #endif cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] != a[a.size() - i - 1]) { cout << "No"; return 0; } } for (int i = 0; i < (a.size() - 1) / 2; i++) { a2.pb(a[i]); } for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) { a3.pb(a[i]); } for (int i = 0; i < a2.size(); i++) { if (a2[i] != a2[a2.size() - i - 1]) { cout << "No"; return 0; } } for (int i = 0; i < a3.size(); i++) { if (a3[i] != a3[a3.size() - i - 1]) { cout << "No"; return 0; } } cout << "Yes"; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define st first #define nd second #define mp make_pair #define pb push_back #define INF 1000000007 #define endl "\n" lli n, m; string a, a2, a3; int main() { cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] != a[a.size() - i - 1]) { cout << "No"; return 0; } } for (int i = 0; i < (a.size() - 1) / 2; i++) { a2.pb(a[i]); } for (int i = (a.size() + 3) / 2 - 1; i < a.size(); i++) { a3.pb(a[i]); } for (int i = 0; i < a2.size(); i++) { if (a2[i] != a2[a2.size() - i - 1]) { cout << "No"; return 0; } } for (int i = 0; i < a3.size(); i++) { if (a3[i] != a3[a3.size() - i - 1]) { cout << "No"; return 0; } } cout << "Yes"; }
delete
15
19
15
15
-11
p02730
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) using namespace std; using ll = long long; int INF = 1001001001; bool isKaibun(string s) { int n = s.length(); int l = n / 2; for (int i = 0; i < l; i++) { if (s[i] != s[n - 1 - i]) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) && isKaibun(s.substr((n + 3) / 2 + 1, n)); if (ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower) using namespace std; using ll = long long; int INF = 1001001001; bool isKaibun(string s) { int n = s.length(); int l = n / 2; for (int i = 0; i < l; i++) { if (s[i] != s[n - 1 - i]) { return false; } } return true; } int main() { string s; cin >> s; int n = s.length(); bool ok = isKaibun(s) && isKaibun(s.substr(0, (n - 1) / 2)) && isKaibun(s.substr((n + 3) / 2 - 1, n)); if (ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
replace
23
24
23
24
0
p02730
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define fastio() ios_base::sync_with_stdio(false) #define rmod(x, y) ((((x) % (y)) + (y)) % (y)) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; template <typename T, typename R = null_type, typename C = less<T>> tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() { return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>(); } int main() { string s; cin >> s; int n = s.size(); string s1 = s.substr(0, ((n - 1) / 2)); string s2 = s.substr((n + 3) / 2 + 1); string rs1 = s1; reverse(rs1.begin(), rs1.end()); string rs2 = s2; reverse(rs2.begin(), rs2.end()); string rs = s; reverse(s.begin(), s.end()); if (s == rs && s1 == rs1 && s2 == rs2) puts("Yes"); else puts("No"); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define fastio() ios_base::sync_with_stdio(false) #define rmod(x, y) ((((x) % (y)) + (y)) % (y)) using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; template <typename T, typename R = null_type, typename C = less<T>> tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set() { return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>(); } int main() { string s; cin >> s; int n = s.size(); string s1 = s.substr(0, ((n - 1) / 2)); string s2 = s.substr((n + 3) / 2 - 1); string rs1 = s1; reverse(rs1.begin(), rs1.end()); string rs2 = s2; reverse(rs2.begin(), rs2.end()); string rs = s; reverse(s.begin(), s.end()); if (s == rs && s1 == rs1 && s2 == rs2) puts("Yes"); else puts("No"); return 0; }
replace
18
19
18
19
0