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
p02710
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; vector<int> C; vector<vector<int>> g; vector<int> res; vector<int> sz; void dfs(int a, int p) { sz[a] = 1; for (int i : g[a]) { if (i != p) { dfs(i, a); sz[a] += sz[i]; } } } int dfs2(int a, int p, map<int, int> &mp, int &add) { int mx = -1; int mxn = -1; for (int i : g[a]) { if (i != p && mx < sz[i]) { mx = sz[i]; mxn = i; } } if (mxn != -1) { dfs2(mxn, a, mp, add); { int t = mp[C[a]] + add; res[C[a]] += t * (t + 1) / 2; } for (int i : g[a]) { if (i != p && i != mxn) { map<int, int> mp2; int add2 = 0; dfs2(i, a, mp2, add2); { int t = mp2[C[a]] + add2; res[C[a]] += t * (t + 1) / 2; } add += add2; for (auto m : mp2) { mp[m.first] += m.second; } } } } add++; mp[C[a]] = -add; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; C.resize(N); g.resize(N); res.resize(N, 0); sz.resize(N); for (int i = 0; i < N; i++) { cin >> C[i]; C[i]--; } for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } dfs(0, -1); map<int, int> mp; int add = 0; dfs2(0, -1, mp, add); for (int i = 0; i < N; i++) { int t = mp[i] + add; res[i] += t * (t + 1) / 2; } int all = N * (N + 1) / 2; for (int i = 0; i < N; i++) { cout << all - res[i] << endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long const int MOD = 1000000007; vector<int> C; vector<vector<int>> g; vector<int> res; vector<int> sz; void dfs(int a, int p) { sz[a] = 1; for (int i : g[a]) { if (i != p) { dfs(i, a); sz[a] += sz[i]; } } } void dfs2(int a, int p, map<int, int> &mp, int &add) { int mx = -1; int mxn = -1; for (int i : g[a]) { if (i != p && mx < sz[i]) { mx = sz[i]; mxn = i; } } if (mxn != -1) { dfs2(mxn, a, mp, add); { int t = mp[C[a]] + add; res[C[a]] += t * (t + 1) / 2; } for (int i : g[a]) { if (i != p && i != mxn) { map<int, int> mp2; int add2 = 0; dfs2(i, a, mp2, add2); { int t = mp2[C[a]] + add2; res[C[a]] += t * (t + 1) / 2; } add += add2; for (auto m : mp2) { mp[m.first] += m.second; } } } } add++; mp[C[a]] = -add; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; C.resize(N); g.resize(N); res.resize(N, 0); sz.resize(N); for (int i = 0; i < N; i++) { cin >> C[i]; C[i]--; } for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } dfs(0, -1); map<int, int> mp; int add = 0; dfs2(0, -1, mp, add); for (int i = 0; i < N; i++) { int t = mp[i] + add; res[i] += t * (t + 1) / 2; } int all = N * (N + 1) / 2; for (int i = 0; i < N; i++) { cout << all - res[i] << endl; } }
replace
18
19
18
19
TLE
p02710
C++
Runtime Error
#include <bits/stdc++.h> #define mset(a, b) memset(a, b, sizeof(a)) #define mcpy(a, b) memcpy(a, b, sizeof(a)) using namespace std; typedef long long LL; const int MAXN = 100005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } AKNOI = flag * x; } int n, m, col[MAXN], has[MAXN]; vector<int> e[MAXN]; int siz[MAXN], sum[MAXN]; LL ans[MAXN]; inline LL C2(int x) { return 1LL * x * (x + 1) / 2; } void DFS(int u, int fa) { siz[u] = 1; for (auto v : e[u]) { if (v == fa) continue; int cur = sum[col[u]]; DFS(v, u); int blk = siz[v] - (sum[col[u]] - cur); ans[col[u]] += C2(blk); sum[col[u]] += blk; siz[u] += siz[v]; } sum[col[u]] += 1; } void init() { read(n); for (int i = 1; i <= n; ++i) { read(col[i]); has[col[i]] = 1; } for (int i = 1, u, v; i < n; ++i) { read(u); read(v); e[u].push_back(v); e[v].push_back(u); } } void solve() { DFS(1, 0); for (int i = 1; i <= n; ++i) { if (i == col[1] || !has[i]) continue; ans[i] += C2(n - sum[i]); } for (int i = 1; i <= n; ++i) { printf("%lld\n", has[i] ? C2(n) - ans[i] : 0); } } int main() { init(); solve(); return 0; }
#include <bits/stdc++.h> #define mset(a, b) memset(a, b, sizeof(a)) #define mcpy(a, b) memcpy(a, b, sizeof(a)) using namespace std; typedef long long LL; const int MAXN = 200005; template <typename T> inline void read(T &AKNOI) { T x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } AKNOI = flag * x; } int n, m, col[MAXN], has[MAXN]; vector<int> e[MAXN]; int siz[MAXN], sum[MAXN]; LL ans[MAXN]; inline LL C2(int x) { return 1LL * x * (x + 1) / 2; } void DFS(int u, int fa) { siz[u] = 1; for (auto v : e[u]) { if (v == fa) continue; int cur = sum[col[u]]; DFS(v, u); int blk = siz[v] - (sum[col[u]] - cur); ans[col[u]] += C2(blk); sum[col[u]] += blk; siz[u] += siz[v]; } sum[col[u]] += 1; } void init() { read(n); for (int i = 1; i <= n; ++i) { read(col[i]); has[col[i]] = 1; } for (int i = 1, u, v; i < n; ++i) { read(u); read(v); e[u].push_back(v); e[v].push_back(u); } } void solve() { DFS(1, 0); for (int i = 1; i <= n; ++i) { if (i == col[1] || !has[i]) continue; ans[i] += C2(n - sum[i]); } for (int i = 1; i <= n; ++i) { printf("%lld\n", has[i] ? C2(n) - ans[i] : 0); } } int main() { init(); solve(); return 0; }
replace
5
6
5
6
0
p02710
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // using ll = int64_t; using ll = long long; using ull = uint64_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = double; #define X first #define Y second #ifndef ONLINE_JUDGE #define FWRITE #endif namespace io { #ifndef FWRITE #include <unistd.h> #endif const int BUFSIZE = 1 << 20; int isize, osize; char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10]; char *is, *it, *os = obuf, *ot = obuf + BUFSIZE; char getchar() { if (is == it) { is = ibuf; #ifdef FWRITE it = ibuf + fread(ibuf, 1, BUFSIZE, stdin); #else it = ibuf + read(STDIN_FILENO, ibuf, BUFSIZE); #endif if (is == it) return EOF; } return *is++; } char getalpha() { char c = getchar(); while (!isalpha(c)) c = getchar(); return c; } void putchar(char c) { *os++ = c; if (os == ot) { #ifdef FWRITE fwrite(obuf, 1, BUFSIZE, stdout); #else write(STDOUT_FILENO, obuf, BUFSIZE); #endif os = obuf; } } int inp() { int x = 0, f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) { if (ch == EOF) return -1; if (ch == '-') f = 1; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return f ? -x : x; } ll inp_ll() { ll x = 0; int f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') f = 1; for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return f ? -x : x; } template <class T> bool read(T &x) { x = 0; char ch = getchar(); if (ch == EOF) return 0; for (; !isdigit(ch);) { ch = getchar(); if (ch == EOF) return 0; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return 1; } template <class T> void write(T x) { static char s[22]; static char *it = s + 20; static char *end = s + 20; if (x < 0) { putchar('-'); x = -x; } do { *--it = x % 10 + '0'; x /= 10; } while (x); /* if (!x) *-- it = '0'; while (x) { *-- it = x%10+'0'; x /= 10; } */ for (; it < end; ++it) putchar(*it); } template <> void write(const char *s) { for (; *s; ++s) putchar(*s); } template <> void write(char c) { putchar(c); } template <class T, class V> void write(T x, V y) { write(x); write(y); } template <class T> void writeln(T x) { write(x); putchar('\n'); } struct ender { ~ender() { if (os != obuf) #ifdef FWRITE fwrite(obuf, 1, os - obuf, stdout); #else write(STDOUT_FILENO, obuf, os - obuf); #endif } } __ender; } // namespace io template <class T> void print(const T &a) { for (auto x : a) printf("%d ", x); puts(""); } int64_t power(int64_t a, int64_t b, int64_t p) { if (!b) return 1; int64_t t = power(a, b >> 1, p); t = t * t % p; if (b & 1) t = t * a % p; return t; } // mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); using namespace io; template <class T> inline void freshmin(T &a, const T &b) { if (a > b) a = b; } template <class T> inline void freshmax(T &a, const T &b) { if (a < b) a = b; } const ll B = 31; const ll MOD = 998244353; const int INF = 1000000010; const int MAXN = 2010; int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; ld det(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3) { return x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3; } ll n; int c[MAXN]; vector<int> v[MAXN], son[MAXN]; int sz[MAXN]; ll ans[MAXN]; using mp = map<int, int>; mp F[MAXN], *H[MAXN]; void go(mp *&a, mp *&b) { if (a->size() < b->size()) swap(a, b); for (auto [x, y] : *b) (*a)[x] += y; } void dfs(int x, int p) { sz[x] = 1; for (auto y : v[x]) { if (y == p) continue; son[x].push_back(y); dfs(y, x); sz[x] += sz[y]; } if (!son[x].empty()) { for (auto y : son[x]) { ll tmp = sz[y]; if ((*H[y]).count(c[x])) { tmp -= (*H[y])[c[x]]; } ans[c[x]] += tmp * (tmp + 1) / 2; } H[x] = H[son[x][0]]; for (int i = 1; i < son[x].size(); ++i) go(H[x], H[son[x][i]]); } else { H[x] = &F[x]; } (*H[x])[c[x]] = sz[x]; // printf("%d:", x); // for (auto [aa, bb] : *H[x]) printf("(%d,%d)", aa, bb); puts(""); } void solve() { n = inp(); for (int i = 1; i <= n; ++i) c[i] = inp(); for (int i = 1; i < n; ++i) { int x = inp(), y = inp(); v[x].push_back(y); v[y].push_back(x); } dfs(1, 0); for (int i = 1; i <= n; ++i) { ll tmp = n; tmp -= (*H[1])[i]; ans[i] += tmp * (tmp + 1) / 2; } for (int i = 1; i <= n; ++i) writeln(n * (n + 1) / 2 - ans[i]); } int main() { // for (int T = inp(); T --; ) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; // using ll = int64_t; using ll = long long; using ull = uint64_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using pii = pair<int, int>; using pll = pair<ll, ll>; using ld = double; #define X first #define Y second #ifndef ONLINE_JUDGE #define FWRITE #endif namespace io { #ifndef FWRITE #include <unistd.h> #endif const int BUFSIZE = 1 << 20; int isize, osize; char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10]; char *is, *it, *os = obuf, *ot = obuf + BUFSIZE; char getchar() { if (is == it) { is = ibuf; #ifdef FWRITE it = ibuf + fread(ibuf, 1, BUFSIZE, stdin); #else it = ibuf + read(STDIN_FILENO, ibuf, BUFSIZE); #endif if (is == it) return EOF; } return *is++; } char getalpha() { char c = getchar(); while (!isalpha(c)) c = getchar(); return c; } void putchar(char c) { *os++ = c; if (os == ot) { #ifdef FWRITE fwrite(obuf, 1, BUFSIZE, stdout); #else write(STDOUT_FILENO, obuf, BUFSIZE); #endif os = obuf; } } int inp() { int x = 0, f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) { if (ch == EOF) return -1; if (ch == '-') f = 1; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return f ? -x : x; } ll inp_ll() { ll x = 0; int f = 0; char ch; for (ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') f = 1; for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return f ? -x : x; } template <class T> bool read(T &x) { x = 0; char ch = getchar(); if (ch == EOF) return 0; for (; !isdigit(ch);) { ch = getchar(); if (ch == EOF) return 0; } for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()) ; return 1; } template <class T> void write(T x) { static char s[22]; static char *it = s + 20; static char *end = s + 20; if (x < 0) { putchar('-'); x = -x; } do { *--it = x % 10 + '0'; x /= 10; } while (x); /* if (!x) *-- it = '0'; while (x) { *-- it = x%10+'0'; x /= 10; } */ for (; it < end; ++it) putchar(*it); } template <> void write(const char *s) { for (; *s; ++s) putchar(*s); } template <> void write(char c) { putchar(c); } template <class T, class V> void write(T x, V y) { write(x); write(y); } template <class T> void writeln(T x) { write(x); putchar('\n'); } struct ender { ~ender() { if (os != obuf) #ifdef FWRITE fwrite(obuf, 1, os - obuf, stdout); #else write(STDOUT_FILENO, obuf, os - obuf); #endif } } __ender; } // namespace io template <class T> void print(const T &a) { for (auto x : a) printf("%d ", x); puts(""); } int64_t power(int64_t a, int64_t b, int64_t p) { if (!b) return 1; int64_t t = power(a, b >> 1, p); t = t * t % p; if (b & 1) t = t * a % p; return t; } // mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count()); mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); using namespace io; template <class T> inline void freshmin(T &a, const T &b) { if (a > b) a = b; } template <class T> inline void freshmax(T &a, const T &b) { if (a < b) a = b; } const ll B = 31; const ll MOD = 998244353; const int INF = 1000000010; const int MAXN = 200010; int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}; int dy[] = {0, 0, -1, 1, -1, 1, -1, 1}; ld det(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3) { return x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3; } ll n; int c[MAXN]; vector<int> v[MAXN], son[MAXN]; int sz[MAXN]; ll ans[MAXN]; using mp = map<int, int>; mp F[MAXN], *H[MAXN]; void go(mp *&a, mp *&b) { if (a->size() < b->size()) swap(a, b); for (auto [x, y] : *b) (*a)[x] += y; } void dfs(int x, int p) { sz[x] = 1; for (auto y : v[x]) { if (y == p) continue; son[x].push_back(y); dfs(y, x); sz[x] += sz[y]; } if (!son[x].empty()) { for (auto y : son[x]) { ll tmp = sz[y]; if ((*H[y]).count(c[x])) { tmp -= (*H[y])[c[x]]; } ans[c[x]] += tmp * (tmp + 1) / 2; } H[x] = H[son[x][0]]; for (int i = 1; i < son[x].size(); ++i) go(H[x], H[son[x][i]]); } else { H[x] = &F[x]; } (*H[x])[c[x]] = sz[x]; // printf("%d:", x); // for (auto [aa, bb] : *H[x]) printf("(%d,%d)", aa, bb); puts(""); } void solve() { n = inp(); for (int i = 1; i <= n; ++i) c[i] = inp(); for (int i = 1; i < n; ++i) { int x = inp(), y = inp(); v[x].push_back(y); v[y].push_back(x); } dfs(1, 0); for (int i = 1; i <= n; ++i) { ll tmp = n; tmp -= (*H[1])[i]; ans[i] += tmp * (tmp + 1) / 2; } for (int i = 1; i <= n; ++i) writeln(n * (n + 1) / 2 - ans[i]); } int main() { // for (int T = inp(); T --; ) solve(); return 0; }
replace
198
199
198
199
0
p02710
C++
Runtime Error
#include <algorithm> #include <cstdio> using namespace std; #define N 200005 #define int long long int n, c[N], num[N], ans[N], C[N]; int tot, head[2 * N], than[2 * N], to[2 * N]; inline int read() { int s = 0, t = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(), t = -1; if (c == '-') c = getchar(), t = -1; while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + (c ^ 48), c = getchar(); return s * t; } void add(int x, int y) { tot++; to[tot] = y; than[tot] = head[x]; head[x] = tot; } void dfs(int now, int p = -1) { int tmp = C[c[now]]; for (int i = head[now]; i; i = than[i]) { int t = to[i]; if (t == p) continue; C[c[i]] = 0; dfs(t, now); num[now] += num[t]; ans[c[now]] -= (num[t] - C[c[now]]) * (num[t] - C[c[now]] + 1) / 2; } C[c[now]] = tmp + num[now]; } signed main(void) { n = read(); for (int i = 0; i < n; i++) c[i] = read(), c[i]--, num[i] = 1; for (int i = 1; i < n; i++) { int x, y; x = read() - 1; y = read() - 1; add(x, y); add(y, x); } dfs(0); for (int i = 0; i < n; i++) { int f = n * (n + 1) / 2; int f1 = (n - C[i]) * (n - C[i] + 1) / 2; printf("%lld\n", ans[i] + f - f1); } // for(int i=0;i<n;i++) // printf("%d ",ans[i]); }
#include <algorithm> #include <cstdio> using namespace std; #define N 200005 #define int long long int n, c[N], num[N], ans[N], C[N]; int tot, head[2 * N], than[2 * N], to[2 * N]; inline int read() { int s = 0, t = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(), t = -1; if (c == '-') c = getchar(), t = -1; while (c >= '0' && c <= '9') s = (s << 1) + (s << 3) + (c ^ 48), c = getchar(); return s * t; } void add(int x, int y) { tot++; to[tot] = y; than[tot] = head[x]; head[x] = tot; } void dfs(int now, int p = -1) { int tmp = C[c[now]]; for (int i = head[now]; i; i = than[i]) { int t = to[i]; if (t == p) continue; C[c[now]] = 0; dfs(t, now); num[now] += num[t]; ans[c[now]] -= (num[t] - C[c[now]]) * (num[t] - C[c[now]] + 1) / 2; } C[c[now]] = tmp + num[now]; } signed main(void) { n = read(); for (int i = 0; i < n; i++) c[i] = read(), c[i]--, num[i] = 1; for (int i = 1; i < n; i++) { int x, y; x = read() - 1; y = read() - 1; add(x, y); add(y, x); } dfs(0); for (int i = 0; i < n; i++) { int f = n * (n + 1) / 2; int f1 = (n - C[i]) * (n - C[i] + 1) / 2; printf("%lld\n", ans[i] + f - f1); } // for(int i=0;i<n;i++) // printf("%d ",ans[i]); }
replace
35
36
35
36
0
p02710
Python
Runtime Error
import sys from collections import defaultdict sys.setrecursionlimit(10**5 + 5) def dfs(v, p, ccc, links, ans): ret_colors = defaultdict(int) ret_count = 1 cv = ccc[v] for u in links[v]: if u == p: continue sub_colors, sub_count = dfs(u, v, ccc, links, ans) cc = sub_count - sub_colors[cv] ans[cv] -= cc * (cc + 1) // 2 ret_count += sub_count if len(ret_colors) < len(sub_colors): ret_colors, sub_colors = sub_colors, ret_colors for c, cnt in sub_colors.items(): ret_colors[c] += cnt ret_colors[cv] = ret_count return ret_colors, ret_count def solve(n, ccc, links): if n == 1: return [1] all_pair = n * (n + 1) // 2 ans = [all_pair] * (n + 1) colors, count = dfs(0, -1, ccc, links, ans) assert count == n for c in range(1, n + 1): cc = n - colors[c] ans[c] -= cc * (cc + 1) // 2 return ans[1:] n, *cab = map(int, sys.stdin.buffer.read().split()) ccc = cab[:n] links = [set() for _ in range(n)] for a, b in zip(cab[n + 0 :: 2], cab[n + 1 :: 2]): a -= 1 b -= 1 links[a].add(b) links[b].add(a) print("\n".join(map(str, solve(n, ccc, links))))
import sys from collections import defaultdict sys.setrecursionlimit(10**6) def dfs(v, p, ccc, links, ans): ret_colors = defaultdict(int) ret_count = 1 cv = ccc[v] for u in links[v]: if u == p: continue sub_colors, sub_count = dfs(u, v, ccc, links, ans) cc = sub_count - sub_colors[cv] ans[cv] -= cc * (cc + 1) // 2 ret_count += sub_count if len(ret_colors) < len(sub_colors): ret_colors, sub_colors = sub_colors, ret_colors for c, cnt in sub_colors.items(): ret_colors[c] += cnt ret_colors[cv] = ret_count return ret_colors, ret_count def solve(n, ccc, links): if n == 1: return [1] all_pair = n * (n + 1) // 2 ans = [all_pair] * (n + 1) colors, count = dfs(0, -1, ccc, links, ans) assert count == n for c in range(1, n + 1): cc = n - colors[c] ans[c] -= cc * (cc + 1) // 2 return ans[1:] n, *cab = map(int, sys.stdin.buffer.read().split()) ccc = cab[:n] links = [set() for _ in range(n)] for a, b in zip(cab[n + 0 :: 2], cab[n + 1 :: 2]): a -= 1 b -= 1 links[a].add(b) links[b].add(a) print("\n".join(map(str, solve(n, ccc, links))))
replace
3
4
3
4
0
p02710
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep2(i, m, n) for (int i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const int MOD = int(1e9) + 7; VV G; V c; Vll ans; pair<ll, map<int, ll>> dfs(int u, int p = -1) { map<int, ll> res; ll sz = 1; for (auto v : G[u]) { if (v == p) continue; auto [sz_v, res_v] = dfs(v, u); ll x = sz_v - res_v[c[u]]; ans[c[u]] -= x * (x + 1) / 2; if (res.size() < res_v.size()) swap(res, res_v); for (auto &&[a, b] : res_v) res[a] += b; sz += sz_v; } res[c[u]] = sz; return {sz, res}; } int main() { ll n; cin >> n; G.assign(n, V()); c.assign(n, 0); ans.assign(n, n * (n + 1) / 2); rep(i, n) { cin >> c[i]; --c[i]; } rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } auto [sz, res] = dfs(0); rep(i, n) { ll x = sz - res[i]; ans[i] -= x * (x + 1) / 2; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep2(i, m, n) for (int i = int(m); i < int(n); ++i) #define drep2(i, m, n) for (int i = int(m - 1); i >= int(n); --i) #define rep(i, n) rep2(i, 0, n) #define drep(i, n) drep2(i, n, 0) #define all(a) a.begin(), a.end() using ll = long long; using ld = long double; using V = vector<int>; using Vll = vector<ll>; using Vld = vector<ld>; using Vbo = vector<bool>; using VV = vector<V>; using VVll = vector<Vll>; using VVld = vector<Vld>; using VVbo = vector<Vbo>; using P = pair<int, int>; using Pll = pair<ll, ll>; using Pld = pair<ld, ld>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << endl; return os; } template <typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits const int INF = 1 << 30; const ll INFll = 1ll << 62; const ld EPS = 1e-10; const int MOD = int(1e9) + 7; VV G; V c; Vll ans; pair<ll, map<int, ll>> dfs(int u, int p = -1) { map<int, ll> res; ll sz = 1; for (auto v : G[u]) { if (v == p) continue; auto [sz_v, res_v] = dfs(v, u); ll x = sz_v - res_v[c[u]]; ans[c[u]] -= x * (x + 1) / 2; if (res.size() < res_v.size()) swap(res, res_v); for (auto &&[a, b] : res_v) res[a] += b; sz += sz_v; } res[c[u]] = sz; return {sz, move(res)}; } int main() { ll n; cin >> n; G.assign(n, V()); c.assign(n, 0); ans.assign(n, n * (n + 1) / 2); rep(i, n) { cin >> c[i]; --c[i]; } rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } auto [sz, res] = dfs(0); rep(i, n) { ll x = sz - res[i]; ans[i] -= x * (x + 1) / 2; } cout << ans; return 0; }
replace
96
97
96
97
TLE
p02710
C++
Runtime Error
// Coded by tzc_wk /* 数据不清空,爆零两行泪。 多测不读完,爆零两行泪。 边界不特判,爆零两行泪。 贪心不证明,爆零两行泪。 D P 顺序错,爆零两行泪。 大小少等号,爆零两行泪。 变量不统一,爆零两行泪。 越界不判断,爆零两行泪。 调试不注释,爆零两行泪。 溢出不 l l,爆零两行泪。 忘文件操作,爆零两行泪。 */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define fz(i, a, b) for (int i = a; i <= b; i++) #define fd(i, a, b) for (int i = a; i >= b; i--) #define foreach(it, v) \ for (__typeof(v.begin()) it = v.begin(); it != v.end(); it++) #define all(a) a.begin(), a.end() #define giveup(...) return printf(__VA_ARGS__), 0; #define fill0(a) memset(a, 0, sizeof(a)) #define fill1(a) memset(a, -1, sizeof(a)) #define fillbig(a) memset(a, 0x3f, sizeof(a)) #define fillsmall(a) memset(a, 0xcf, sizeof(a)) #define mask(a) (1ll << (a)) #define maskx(a, x) ((a) << (x)) #define _bit(a, x) (((a) >> (x)) & 1) #define _sz(a) ((int)(a).size()) #define filei(a) freopen(a, "r", stdin); #define fileo(a) freopen(a, "w", stdout); #define fileio(a) \ freopen(a ".in", "r", stdin); \ freopen(a ".out", "w", stdout) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define put(x) putchar(x) #define eoln put('\n') #define space put(' ') #define y1 y_chenxiaoyan_1 #define y0 y_chenxiaoyan_0 #define int long long typedef pair<int, int> pii; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline void print(int x) { if (x < 0) { putchar('-'); print(abs(x)); return; } if (x <= 9) putchar(x + '0'); else { print(x / 10); putchar(x % 10 + '0'); } } inline int qpow(int x, int e, int _MOD) { int ans = 1; while (e) { if (e & 1) ans = ans * x % _MOD; x = x * x % _MOD; e >>= 1; } return ans; } int n = read(), a[100005]; int sz[100005]; vector<int> g[100005]; map<int, int> dp[100005]; vector<int> res[100005]; inline void dfs(int x, int f) { sz[x] = 1; foreach (it, g[x]) { int y = *it; if (y == f) continue; dfs(y, x); sz[x] += sz[y]; int t = sz[y]; if (dp[y].count(a[x])) t -= dp[y][a[x]]; res[a[x]].push_back(t); // cout<<"add "<<a[x]<<" "<<t<<endl; if (dp[x].size() < dp[y].size()) swap(dp[x], dp[y]); foreach (it2, dp[y]) dp[x][it2->first] += it2->second; } dp[x][a[x]] = sz[x]; // cout<<x<<"\t"; // fz(i,1,n) cout<<dp[x][i]<<" ";puts(""); } signed main() { fz(i, 1, n) a[i] = read(); fz(i, 1, n - 1) { int u = read(), v = read(); g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); fz(i, 1, n) res[i].push_back(n - dp[1][i]); fz(i, 1, n) { int sum = (n * (n + 1)) / 2; foreach (it, res[i]) { // cout<<*it<<" "; sum -= (*it) * ((*it) + 1) / 2; } // puts(""); cout << sum << endl; } return 0; }
// Coded by tzc_wk /* 数据不清空,爆零两行泪。 多测不读完,爆零两行泪。 边界不特判,爆零两行泪。 贪心不证明,爆零两行泪。 D P 顺序错,爆零两行泪。 大小少等号,爆零两行泪。 变量不统一,爆零两行泪。 越界不判断,爆零两行泪。 调试不注释,爆零两行泪。 溢出不 l l,爆零两行泪。 忘文件操作,爆零两行泪。 */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define fz(i, a, b) for (int i = a; i <= b; i++) #define fd(i, a, b) for (int i = a; i >= b; i--) #define foreach(it, v) \ for (__typeof(v.begin()) it = v.begin(); it != v.end(); it++) #define all(a) a.begin(), a.end() #define giveup(...) return printf(__VA_ARGS__), 0; #define fill0(a) memset(a, 0, sizeof(a)) #define fill1(a) memset(a, -1, sizeof(a)) #define fillbig(a) memset(a, 0x3f, sizeof(a)) #define fillsmall(a) memset(a, 0xcf, sizeof(a)) #define mask(a) (1ll << (a)) #define maskx(a, x) ((a) << (x)) #define _bit(a, x) (((a) >> (x)) & 1) #define _sz(a) ((int)(a).size()) #define filei(a) freopen(a, "r", stdin); #define fileo(a) freopen(a, "w", stdout); #define fileio(a) \ freopen(a ".in", "r", stdin); \ freopen(a ".out", "w", stdout) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #define put(x) putchar(x) #define eoln put('\n') #define space put(' ') #define y1 y_chenxiaoyan_1 #define y0 y_chenxiaoyan_0 #define int long long typedef pair<int, int> pii; inline int read() { int x = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) x = x * 10 + c - '0', c = getchar(); return x * neg; } inline void print(int x) { if (x < 0) { putchar('-'); print(abs(x)); return; } if (x <= 9) putchar(x + '0'); else { print(x / 10); putchar(x % 10 + '0'); } } inline int qpow(int x, int e, int _MOD) { int ans = 1; while (e) { if (e & 1) ans = ans * x % _MOD; x = x * x % _MOD; e >>= 1; } return ans; } int n = read(), a[200005]; int sz[200005]; vector<int> g[200005]; map<int, int> dp[200005]; vector<int> res[200005]; inline void dfs(int x, int f) { sz[x] = 1; foreach (it, g[x]) { int y = *it; if (y == f) continue; dfs(y, x); sz[x] += sz[y]; int t = sz[y]; if (dp[y].count(a[x])) t -= dp[y][a[x]]; res[a[x]].push_back(t); // cout<<"add "<<a[x]<<" "<<t<<endl; if (dp[x].size() < dp[y].size()) swap(dp[x], dp[y]); foreach (it2, dp[y]) dp[x][it2->first] += it2->second; } dp[x][a[x]] = sz[x]; // cout<<x<<"\t"; // fz(i,1,n) cout<<dp[x][i]<<" ";puts(""); } signed main() { fz(i, 1, n) a[i] = read(); fz(i, 1, n - 1) { int u = read(), v = read(); g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); fz(i, 1, n) res[i].push_back(n - dp[1][i]); fz(i, 1, n) { int sum = (n * (n + 1)) / 2; foreach (it, res[i]) { // cout<<*it<<" "; sum -= (*it) * ((*it) + 1) / 2; } // puts(""); cout << sum << endl; } return 0; }
replace
80
85
80
85
0
p02710
C++
Runtime Error
// ref. https://www.youtube.com/watch?v=HVuSp_IhNZA #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T> void printvec(const vector<T> &v) { for (auto x : v) { cout << x << " "; } cout << endl; } template <class T> void printtree(const vector<vector<T>> &tree) { for (long long i = 0; i < tree.size(); ++i) { cout << i + 1 << ": "; printvec(tree[i]); } } template <class T, class U> void printmap(const map<T, U> &mp) { for (auto x : mp) { cout << x.first << "=>" << x.second << endl; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(s) s.begin(), s.end() #define fr first #define sc second #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> triple; typedef double D; const ll INF = 1e9; const ll MOD = 1000000007; // 1e9 + 7 vector<ll> c; vector<vector<ll>> g; vector<ll> t; // t[i] .. size of subtree with root i vector<stack<ll>> st; vector<ll> d; // d[i] .. temporary store. vector<ll> remsz; // remsz[i] .. remaining size of color i vector<ll> ans; // ans[i] .. result of color i ll f(ll n) { return n * (n + 1) / 2; } // nC2 + n = n*(n+1)/2 ll tfs(ll v, ll p = -1) { t[v] = 1; for (int u : g[v]) { if (u == p) { continue; } t[v] += tfs(u, v); } return t[v]; } void dfs(ll v, ll p = -1) { st[c[v]].push(v); for (ll u : g[v]) { if (u == p) { continue; } d[v] = t[u]; // store here temporarily dfs(u, v); ans[c[v]] -= f(d[v]); } st[c[v]].pop(); if (st[c[v]].size() > 0) { d[st[c[v]].top()] -= t[v]; // decrease the contribution of this subtree } else { remsz[c[v]] -= t[v]; } } int main(int argc, char **argv) { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); // cout << setprecision(10) << fixed; ll n; cin >> n; c.resize(n); g.resize(n); t.resize(n); st.resize(n); d.resize(n); remsz.resize(n); ans.resize(n); rep(i, n) { cin >> c[i]; } rep(i, n - 1) { ll a, b; cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a); } rep(i, n) { ans[i] = f(n); } rep(i, n) { remsz[i] = n; } tfs(0); dfs(0); rep(i, n) { ans[i] -= f(remsz[i]); } rep(i, n) { cout << ans[i] << endl; } }
// ref. https://www.youtube.com/watch?v=HVuSp_IhNZA #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <unordered_map> #include <vector> using namespace std; #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl template <class T> void printvec(const vector<T> &v) { for (auto x : v) { cout << x << " "; } cout << endl; } template <class T> void printtree(const vector<vector<T>> &tree) { for (long long i = 0; i < tree.size(); ++i) { cout << i + 1 << ": "; printvec(tree[i]); } } template <class T, class U> void printmap(const map<T, U> &mp) { for (auto x : mp) { cout << x.first << "=>" << x.second << endl; } } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(s) s.begin(), s.end() #define fr first #define sc second #define mp make_pair #define pb push_back typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> triple; typedef double D; const ll INF = 1e9; const ll MOD = 1000000007; // 1e9 + 7 vector<ll> c; vector<vector<ll>> g; vector<ll> t; // t[i] .. size of subtree with root i vector<stack<ll>> st; vector<ll> d; // d[i] .. temporary store. vector<ll> remsz; // remsz[i] .. remaining size of color i vector<ll> ans; // ans[i] .. result of color i ll f(ll n) { return n * (n + 1) / 2; } // nC2 + n = n*(n+1)/2 ll tfs(ll v, ll p = -1) { t[v] = 1; for (int u : g[v]) { if (u == p) { continue; } t[v] += tfs(u, v); } return t[v]; } void dfs(ll v, ll p = -1) { st[c[v]].push(v); for (ll u : g[v]) { if (u == p) { continue; } d[v] = t[u]; // store here temporarily dfs(u, v); ans[c[v]] -= f(d[v]); } st[c[v]].pop(); if (st[c[v]].size() > 0) { d[st[c[v]].top()] -= t[v]; // decrease the contribution of this subtree } else { remsz[c[v]] -= t[v]; } } int main(int argc, char **argv) { cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); // cout << setprecision(10) << fixed; ll n; cin >> n; c.resize(n); g.resize(n); t.resize(n); st.resize(n); d.resize(n); remsz.resize(n); ans.resize(n); rep(i, n) { cin >> c[i]; --c[i]; } rep(i, n - 1) { ll a, b; cin >> a >> b; --a; --b; g[a].push_back(b); g[b].push_back(a); } rep(i, n) { ans[i] = f(n); } rep(i, n) { remsz[i] = n; } tfs(0); dfs(0); rep(i, n) { ans[i] -= f(remsz[i]); } rep(i, n) { cout << ans[i] << endl; } }
replace
126
127
126
130
0
p02710
C++
Runtime Error
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; 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 (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int N; int C[210]; vector<int> G[210]; vector<int> ET; void dfs(int idx, int par) { bool ok = false; for (auto e : G[idx]) { if (e == par) continue; ok = true; ET.push_back(idx); dfs(e, idx); ET.push_back(-idx); } if (!ok) { ET.push_back(idx); ET.push_back(-idx); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, 0, N) { cin >> C[i + 1]; C[i + 1]--; } int a, b; rep(i, 0, N - 1) { cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } dfs(1, -1); vector<int> SSZ(SZ(ET)); set<int> iset; vector<map<int, int>> STCM(N); vector<map<int, int>> PM(N); vector<stack<int>> CS(N); vector<int> NGC(N, 0); rep(i, 0, N) { STCM[i][0] = 0; PM[i][0] = 0; CS[i].push(0); } rep(i, 0, SZ(ET)) { if (ET[i] > 0) { iset.insert(ET[i]); } SSZ[i] = SZ(iset); if (ET[i] > 0) { CS[C[ET[i]]].push(ET[i]); PM[C[ET[i]]][ET[i]] = i; STCM[C[ET[i]]][ET[i]] = 0; } else { CS[C[-ET[i]]].pop(); int par = CS[C[-ET[i]]].top(); int sz = SSZ[i - 1] - SSZ[PM[C[-ET[i]]][-ET[i]]]; int ngsz = sz - STCM[C[-ET[i]]][-ET[i]]; NGC[C[-ET[i]]] += ngsz * (ngsz + 1) / 2; if (i == SZ(ET) - 1 || ET[i + 1] != -ET[i]) sz++; STCM[C[-ET[i]]][par] += sz; } } rep(i, 0, N) { int ngsz = N - STCM[i][0]; NGC[i] += ngsz * (ngsz + 1) / 2; int res = N * (N + 1) / 2 - NGC[i]; cout << res << endl; } return 0; }
// #include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair // typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; 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 (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int N; int C[200010]; vector<int> G[200010]; vector<int> ET; void dfs(int idx, int par) { bool ok = false; for (auto e : G[idx]) { if (e == par) continue; ok = true; ET.push_back(idx); dfs(e, idx); ET.push_back(-idx); } if (!ok) { ET.push_back(idx); ET.push_back(-idx); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; rep(i, 0, N) { cin >> C[i + 1]; C[i + 1]--; } int a, b; rep(i, 0, N - 1) { cin >> a >> b; G[a].push_back(b); G[b].push_back(a); } dfs(1, -1); vector<int> SSZ(SZ(ET)); set<int> iset; vector<map<int, int>> STCM(N); vector<map<int, int>> PM(N); vector<stack<int>> CS(N); vector<int> NGC(N, 0); rep(i, 0, N) { STCM[i][0] = 0; PM[i][0] = 0; CS[i].push(0); } rep(i, 0, SZ(ET)) { if (ET[i] > 0) { iset.insert(ET[i]); } SSZ[i] = SZ(iset); if (ET[i] > 0) { CS[C[ET[i]]].push(ET[i]); PM[C[ET[i]]][ET[i]] = i; STCM[C[ET[i]]][ET[i]] = 0; } else { CS[C[-ET[i]]].pop(); int par = CS[C[-ET[i]]].top(); int sz = SSZ[i - 1] - SSZ[PM[C[-ET[i]]][-ET[i]]]; int ngsz = sz - STCM[C[-ET[i]]][-ET[i]]; NGC[C[-ET[i]]] += ngsz * (ngsz + 1) / 2; if (i == SZ(ET) - 1 || ET[i + 1] != -ET[i]) sz++; STCM[C[-ET[i]]][par] += sz; } } rep(i, 0, N) { int ngsz = N - STCM[i][0]; NGC[i] += ngsz * (ngsz + 1) / 2; int res = N * (N + 1) / 2 - NGC[i]; cout << res << endl; } return 0; }
replace
68
70
68
70
0
p02710
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF (1 << 29) #define LINF (1LL << 60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 typedef long long Int; typedef pair<Int, Int> P; typedef long double Real; typedef complex<Real> CP; Int n; vector<Int> edge[220000]; Int c[220000]; Int ans[220000]; int last_c[220000]; Int tree_size[220000]; Int parent[220000]; Int no_parent_cnt[220000]; vector<int> children[22000]; Int cnt(Int a) { return a * (a - 1) / 2 + a; } void dfs(int x, int last = -1) { parent[x] = last_c[c[x]]; last_c[c[x]] = x; if (parent[x] != -1) { children[parent[x]].push_back(x); } tree_size[x] = 1; for (auto to : edge[x]) { if (to == last) continue; dfs(to, x); tree_size[x] += tree_size[to]; Int tmp = tree_size[to]; for (auto child : children[x]) { tmp -= tree_size[child]; } children[x].clear(); ans[c[x]] -= cnt(tmp); } if (parent[x] == -1) { no_parent_cnt[c[x]] -= tree_size[x]; } last_c[c[x]] = parent[x]; } int main() { cin >> n; fill(last_c, last_c + 220000, -1); fill(no_parent_cnt, no_parent_cnt + 220000, n); fill(ans, ans + n, cnt(n)); for (int i = 0; i < n; i++) { cin >> c[i]; c[i]--; } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; edge[u].push_back(v); edge[v].push_back(u); } dfs(0); for (int i = 0; i < n; i++) { ans[i] -= cnt(no_parent_cnt[i]); cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define MOD2 998244353 #define INF (1 << 29) #define LINF (1LL << 60) #define EPS (1e-10) #define PI 3.1415926535897932384626433832795028 typedef long long Int; typedef pair<Int, Int> P; typedef long double Real; typedef complex<Real> CP; Int n; vector<Int> edge[220000]; Int c[220000]; Int ans[220000]; int last_c[220000]; Int tree_size[220000]; Int parent[220000]; Int no_parent_cnt[220000]; vector<int> children[220000]; Int cnt(Int a) { return a * (a - 1) / 2 + a; } void dfs(int x, int last = -1) { parent[x] = last_c[c[x]]; last_c[c[x]] = x; if (parent[x] != -1) { children[parent[x]].push_back(x); } tree_size[x] = 1; for (auto to : edge[x]) { if (to == last) continue; dfs(to, x); tree_size[x] += tree_size[to]; Int tmp = tree_size[to]; for (auto child : children[x]) { tmp -= tree_size[child]; } children[x].clear(); ans[c[x]] -= cnt(tmp); } if (parent[x] == -1) { no_parent_cnt[c[x]] -= tree_size[x]; } last_c[c[x]] = parent[x]; } int main() { cin >> n; fill(last_c, last_c + 220000, -1); fill(no_parent_cnt, no_parent_cnt + 220000, n); fill(ans, ans + n, cnt(n)); for (int i = 0; i < n; i++) { cin >> c[i]; c[i]--; } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; edge[u].push_back(v); edge[v].push_back(u); } dfs(0); for (int i = 0; i < n; i++) { ans[i] -= cnt(no_parent_cnt[i]); cout << ans[i] << endl; } return 0; }
replace
31
32
31
32
0
p02710
C++
Runtime Error
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fm, to) for (int i = fm; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = int(2e5); bool vis[nsz + 5]; int n, rt = 1, a[nsz + 5], pr[nsz + 5]; vector<int> p[nsz + 5]; struct link_cut_tree { #define dir(u) (rs[pr[u]] == u) #define s(u, d) (d ? rs[u] : ls[u]) #define is_rt(u) (ls[pr[u]] != u && rs[pr[u]] != u) bool rev[nsz + 5]; int sz, pr[nsz + 5], ls[nsz + 5], rs[nsz + 5]; int siz[nsz + 5], vsz[nsz + 5]; void inline up(int u) { siz[u] = siz[ls[u]] + siz[rs[u]] + 1 + vsz[u]; } void inline down(int u) { if (rev[u]) { int v1 = ls[u], v2 = rs[u]; if (v1) swap(ls[v1], rs[v1]), rev[v1] ^= 1; if (v2) swap(ls[v2], rs[v2]), rev[v2] ^= 1; rev[u] = 0; } } void inline push_down(int u) { static int stk[nsz + 5]; int s = 0; for (; !is_rt(u); stk[s++] = u, u = pr[u]) ; for (stk[s++] = u; s; down(stk[--s])) ; } void inline rotate(int u) { int p = pr[u], g = pr[p], d = dir(u), v = s(u, !d); !is_rt(p) && (s(g, dir(p)) = u); pr[u] = g; s(p, d) = v, pr[v] = p; s(u, !d) = p, pr[p] = u; up(p), up(u); } void inline splay(int u) { push_down(u); for (int p = pr[u]; !is_rt(u); rotate(u), p = pr[u]) { if (!is_rt(p)) rotate(dir(u) != dir(p) ? u : p); } } int inline access(int u) { int v = 0; for (; u; v = u, u = pr[u]) { splay(u); vsz[u] += siz[rs[u]] - siz[v]; rs[u] = v, up(u); } return v; } void inline set_rt(int u) { u = access(u); swap(ls[u], rs[u]), rev[u] ^= 1; } int inline rt_of(int u) { u = access(u); for (; ls[u]; down(u), u = ls[u]) ; splay(u); return u; } bool inline link(int u, int v) { set_rt(u); if (rt_of(v) == u) return 0; splay(v); rs[v] = u, pr[u] = v; up(v); return 1; } bool inline cut(int u, int v) { set_rt(u), access(v), splay(v); if (ls[v] != u) return 0; pr[u] = ls[v] = 0; up(u); return 1; } int inline node() { int u = ++sz; ls[u] = rs[u] = siz[u] = vsz[u] = rev[u] = 0; return u; } }; link_cut_tree tr; struct graph { int sz, hd[nsz + 5]; struct edge { int nxt, to; edge(int nxt = 0, int to = 0) { this->nxt = nxt, this->to = to; } } e[2 * nsz + 5]; inline edge &operator[](int id) { return e[id]; } void inline link(int u, int v) { e[++sz] = edge(hd[u], v), hd[u] = sz; e[++sz] = edge(hd[v], u), hd[v] = sz; } }; graph g; int main() { scanf("%d", &n); cont(i, n) { scanf("%d", &a[i]); tr.node(); p[a[i]].push_back(i); } cont(i, n - 1) { int u, v; scanf("%d%d", &u, &v); g.link(u, v); tr.link(u, v); } cont(c, n) { if (!p[c].size()) { printf("0\n"); continue; } loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to; tr.cut(u, v); } } num res = (num)n * (n + 1) / 2; static int stk[nsz + 5]; int s = 0; loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to, p = tr.rt_of(v), sz = tr.siz[p]; if (v == pr[u] || a[v] == c || vis[p]) continue; res -= (num)sz * (sz + 1) / 2; vis[p] = 1; stk[s++] = p; } } printf("%lld\n", res); loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to; tr.link(u, v); } } for (; s; vis[stk[--s]] = 0) ; } }
#include <bits/stdc++.h> #define ln '\n' #define all(dat) dat.begin(), dat.end() #define loop(i, to) for (int i = 0; i < to; ++i) #define cont(i, to) for (int i = 1; i <= to; ++i) #define circ(i, fm, to) for (int i = fm; i <= to; ++i) #define foreach(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) typedef long long num; using namespace std; const int nsz = int(2e5); bool vis[nsz + 5]; int n, rt = 1, a[nsz + 5], pr[nsz + 5]; vector<int> p[nsz + 5]; struct link_cut_tree { #define dir(u) (rs[pr[u]] == u) #define s(u, d) (d ? rs[u] : ls[u]) #define is_rt(u) (ls[pr[u]] != u && rs[pr[u]] != u) bool rev[nsz + 5]; int sz, pr[nsz + 5], ls[nsz + 5], rs[nsz + 5]; int siz[nsz + 5], vsz[nsz + 5]; void inline up(int u) { siz[u] = siz[ls[u]] + siz[rs[u]] + 1 + vsz[u]; } void inline down(int u) { if (rev[u]) { int v1 = ls[u], v2 = rs[u]; if (v1) swap(ls[v1], rs[v1]), rev[v1] ^= 1; if (v2) swap(ls[v2], rs[v2]), rev[v2] ^= 1; rev[u] = 0; } } void inline push_down(int u) { static int stk[nsz + 5]; int s = 0; for (; !is_rt(u); stk[s++] = u, u = pr[u]) ; for (stk[s++] = u; s; down(stk[--s])) ; } void inline rotate(int u) { int p = pr[u], g = pr[p], d = dir(u), v = s(u, !d); !is_rt(p) && (s(g, dir(p)) = u); pr[u] = g; s(p, d) = v, pr[v] = p; s(u, !d) = p, pr[p] = u; up(p), up(u); } void inline splay(int u) { push_down(u); for (int p = pr[u]; !is_rt(u); rotate(u), p = pr[u]) { if (!is_rt(p)) rotate(dir(u) != dir(p) ? u : p); } } int inline access(int u) { int v = 0; for (; u; v = u, u = pr[u]) { splay(u); vsz[u] += siz[rs[u]] - siz[v]; rs[u] = v, up(u); } return v; } void inline set_rt(int u) { access(u), splay(u); swap(ls[u], rs[u]), rev[u] ^= 1; } int inline rt_of(int u) { u = access(u); for (; ls[u]; down(u), u = ls[u]) ; splay(u); return u; } bool inline link(int u, int v) { set_rt(u); if (rt_of(v) == u) return 0; splay(v); rs[v] = u, pr[u] = v; up(v); return 1; } bool inline cut(int u, int v) { set_rt(u), access(v), splay(v); if (ls[v] != u) return 0; pr[u] = ls[v] = 0; up(u); return 1; } int inline node() { int u = ++sz; ls[u] = rs[u] = siz[u] = vsz[u] = rev[u] = 0; return u; } }; link_cut_tree tr; struct graph { int sz, hd[nsz + 5]; struct edge { int nxt, to; edge(int nxt = 0, int to = 0) { this->nxt = nxt, this->to = to; } } e[2 * nsz + 5]; inline edge &operator[](int id) { return e[id]; } void inline link(int u, int v) { e[++sz] = edge(hd[u], v), hd[u] = sz; e[++sz] = edge(hd[v], u), hd[v] = sz; } }; graph g; int main() { scanf("%d", &n); cont(i, n) { scanf("%d", &a[i]); tr.node(); p[a[i]].push_back(i); } cont(i, n - 1) { int u, v; scanf("%d%d", &u, &v); g.link(u, v); tr.link(u, v); } cont(c, n) { if (!p[c].size()) { printf("0\n"); continue; } loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to; tr.cut(u, v); } } num res = (num)n * (n + 1) / 2; static int stk[nsz + 5]; int s = 0; loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to, p = tr.rt_of(v), sz = tr.siz[p]; if (v == pr[u] || a[v] == c || vis[p]) continue; res -= (num)sz * (sz + 1) / 2; vis[p] = 1; stk[s++] = p; } } printf("%lld\n", res); loop(i, p[c].size()) { int u = p[c][i]; for (int i = g.hd[u]; i; i = g[i].nxt) { int v = g[i].to; tr.link(u, v); } } for (; s; vis[stk[--s]] = 0) ; } }
replace
79
80
79
80
0
p02710
C++
Runtime Error
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define int64 long long #define pii pair<int64, int64> #define fr first #define sc second #define heap priority_queue struct piii { int64 fr, sc, th; bool operator<(const piii &b) { if (fr != b.fr) return fr < b.fr; if (sc != b.sc) return sc < b.sc; return th < b.th; } }; /////////////////////////////////////////////// /////////////////////////////////////////////// const int maxn = 1e5 + 5; int n, ccc; int c[maxn], l[maxn], r[maxn], cnt[maxn], h[maxn], p[maxn]; int lz[maxn * 4], sum[maxn * 4]; vector<int> d[maxn], e[maxn], a; void input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> c[i]; d[c[i]].push_back(i); } int u, v; for (int i = 1; i < n; i++) { cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } } void dfs(int u) { l[u] = ++ccc; for (int v : e[u]) if (v != p[u]) { h[v] = h[u] + 1; p[v] = u; dfs(v); cnt[u] += cnt[v]; } cnt[u]++; r[u] = ccc; } bool cmp(const int &a, const int &b) { return h[a] > h[b]; } void mdf(int id, int l, int r, int val) { if (val == -1) return; lz[id] = val; sum[id] = (r - l + 1) * val; } void up(int id, int l, int r, int u, int v, int val) { if (v < l || u > r) return; if (l >= u && r <= v) { mdf(id, l, r, val); return; } int mid = (l + r) >> 1; mdf(id * 2, l, mid, lz[id]); mdf(id * 2 + 1, mid + 1, r, lz[id]); lz[id] = -1; up(id * 2, l, mid, u, v, val); up(id * 2 + 1, mid + 1, r, u, v, val); sum[id] = sum[id * 2] + sum[id * 2 + 1]; } int get(int id, int l, int r, int u, int v) { if (v < l || u > r) return 0; if (l >= u && r <= v) return sum[id]; int mid = (l + r) >> 1; mdf(id * 2, l, mid, lz[id]); mdf(id * 2 + 1, mid + 1, r, lz[id]); return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v); } int main() { cout << setprecision(2) << fixed; ios::sync_with_stdio(false), cin.tie(0); // freopen("input.txt", "r", stdin); input(); dfs(1); for (int i = 1; i <= n; i++) { sort(d[i].begin(), d[i].end(), cmp); up(1, 1, n, 1, n, 1); int64 nn = n, res = 0; for (int j = 0; j < d[i].size(); j++) { int u = d[i][j]; a.clear(); int64 tsum = 0; for (int v : e[u]) if (v != p[u]) { a.push_back(get(1, 1, n, l[v], r[v])); tsum += a[a.size() - 1]; } for (int64 t : a) { res += t * (tsum - t); tsum -= t; } int64 tmp = get(1, 1, n, l[d[i][j]], r[d[i][j]]); up(1, 1, n, l[d[i][j]], r[d[i][j]], 0); nn -= tmp; res += tmp * (nn + 1); } cout << res << endl; } return 0; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <vector> using namespace std; #define int64 long long #define pii pair<int64, int64> #define fr first #define sc second #define heap priority_queue struct piii { int64 fr, sc, th; bool operator<(const piii &b) { if (fr != b.fr) return fr < b.fr; if (sc != b.sc) return sc < b.sc; return th < b.th; } }; /////////////////////////////////////////////// /////////////////////////////////////////////// const int maxn = 2e5 + 5; int n, ccc; int c[maxn], l[maxn], r[maxn], cnt[maxn], h[maxn], p[maxn]; int lz[maxn * 4], sum[maxn * 4]; vector<int> d[maxn], e[maxn], a; void input() { cin >> n; for (int i = 1; i <= n; i++) { cin >> c[i]; d[c[i]].push_back(i); } int u, v; for (int i = 1; i < n; i++) { cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } } void dfs(int u) { l[u] = ++ccc; for (int v : e[u]) if (v != p[u]) { h[v] = h[u] + 1; p[v] = u; dfs(v); cnt[u] += cnt[v]; } cnt[u]++; r[u] = ccc; } bool cmp(const int &a, const int &b) { return h[a] > h[b]; } void mdf(int id, int l, int r, int val) { if (val == -1) return; lz[id] = val; sum[id] = (r - l + 1) * val; } void up(int id, int l, int r, int u, int v, int val) { if (v < l || u > r) return; if (l >= u && r <= v) { mdf(id, l, r, val); return; } int mid = (l + r) >> 1; mdf(id * 2, l, mid, lz[id]); mdf(id * 2 + 1, mid + 1, r, lz[id]); lz[id] = -1; up(id * 2, l, mid, u, v, val); up(id * 2 + 1, mid + 1, r, u, v, val); sum[id] = sum[id * 2] + sum[id * 2 + 1]; } int get(int id, int l, int r, int u, int v) { if (v < l || u > r) return 0; if (l >= u && r <= v) return sum[id]; int mid = (l + r) >> 1; mdf(id * 2, l, mid, lz[id]); mdf(id * 2 + 1, mid + 1, r, lz[id]); return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v); } int main() { cout << setprecision(2) << fixed; ios::sync_with_stdio(false), cin.tie(0); // freopen("input.txt", "r", stdin); input(); dfs(1); for (int i = 1; i <= n; i++) { sort(d[i].begin(), d[i].end(), cmp); up(1, 1, n, 1, n, 1); int64 nn = n, res = 0; for (int j = 0; j < d[i].size(); j++) { int u = d[i][j]; a.clear(); int64 tsum = 0; for (int v : e[u]) if (v != p[u]) { a.push_back(get(1, 1, n, l[v], r[v])); tsum += a[a.size() - 1]; } for (int64 t : a) { res += t * (tsum - t); tsum -= t; } int64 tmp = get(1, 1, n, l[d[i][j]], r[d[i][j]]); up(1, 1, n, l[d[i][j]], r[d[i][j]], 0); nn -= tmp; res += tmp * (nn + 1); } cout << res << endl; } return 0; }
replace
32
33
32
33
0
p02710
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define all(x) x.begin(), x.end() template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; } #define int ll const int MAXN = 200; vector<int> g[MAXN]; vector<int> c[MAXN]; int n; void read() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x--; c[x].push_back(i); } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } } int tin[MAXN], timer = 0; int tout[MAXN]; int sz[MAXN]; const int MAXLOG = 20; int dp[MAXN][MAXLOG]; int help_sum[MAXN]; int get(int n) { if (n < 0) return 0; return n * (n - 1) / 2 + n; } void dfs(int v, int p) { tin[v] = timer++; sz[v] = 1; dp[v][0] = p; for (int i = 1; i < MAXLOG; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1]; for (auto i : g[v]) { if (i == p) continue; dfs(i, v); help_sum[v] += get(sz[i]); sz[v] += sz[i]; } tout[v] = timer; } bool is_upper(int v, int u) { return tin[v] <= tin[u] && tout[v] >= tout[u]; } int lca(int v, int u) { if (is_upper(v, u)) return v; if (is_upper(u, v)) return u; for (int i = MAXLOG - 1; i >= 0; i--) if (!is_upper(dp[v][i], u)) v = dp[v][i]; return dp[v][0]; } int pre_lca(int p, int v) { for (int i = MAXLOG - 1; i >= 0; i--) if (!is_upper(dp[v][i], p)) v = dp[v][i]; return v; } int ans[MAXN]; vector<int> get_all_vert(vector<int> &v) { sort(all(v), [&](int a, int b) { return tin[a] < tin[b]; }); v.resize(unique(all(v)) - v.begin()); vector<int> have = v; int n = v.size(); for (int i = 0; i < n - 1; i++) { have.push_back(lca(have[i], have[i + 1])); } sort(all(have), [&](int a, int b) { return tin[a] < tin[b]; }); have.resize(unique(all(have)) - have.begin()); return have; } vector<vector<int>> build_tree(vector<int> &have) { int n = have.size(); vector<vector<int>> tree(n); vector<pair<int, int>> st; for (int i = 0; i < n; i++) { while (!st.empty() && !is_upper(st.back().first, have[i])) st.pop_back(); if (!st.empty()) { tree[st.back().second].push_back(i); } st.push_back({have[i], i}); } return tree; } bool cmp(int a, int b) { return tin[a] < tin[b]; } int dfs_calc(int v, vector<vector<int>> &g, vector<int> &have, vector<int> &good, int &fans) { bool flag = false; int pos = lower_bound(all(good), have[v], cmp) - good.begin(); if (pos >= 0 && pos < (int)good.size() && good[pos] == have[v]) { flag = true; } int cnt = 0; if (flag) { cnt = sz[have[v]]; } int other = help_sum[have[v]]; for (auto i : g[v]) { int now = dfs_calc(i, g, have, good, fans); if (flag) { int x = get(sz[pre_lca(have[v], have[i])] - now); fans += x; other -= get(sz[pre_lca(have[v], have[i])]); } else { cnt += now; } } if (flag) { fans += other; } return cnt; } int calc(vector<int> v) { if (v.empty()) return get(n); vector<int> have = get_all_vert(v); /*cout << "have = " << endl; for (auto i : have) { cout << i << " "; } cout << endl;*/ vector<vector<int>> g = build_tree(have); /*cout << "g = " << endl; for (auto i : g) { for (auto j : i) { cout << j << " "; } cout << endl; }*/ int ans = 0; int now = dfs_calc(0, g, have, v, ans); // cout << "ans = " << ans << endl; // cout << now << endl; ans += get(sz[0] - now); return ans; } void run() { dfs(0, 0); // cout << get(n) - calc(c[0]) << endl; // exit(0); for (int i = 0; i < n; i++) { ans[i] = get(n) - calc(c[i]); } // cout << "puhh" << endl; } void write() { for (int i = 0; i < n; i++) cout << ans[i] << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read(); run(); write(); return 0; } /* WA 128 input = 6 1 2 1 1 3 1 1 2 2 3 1 4 1 5 2 6 ans = 13 0 0 6 0 19 out = 13 0 0 6 0 20 */
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; #define all(x) x.begin(), x.end() template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; } #define int ll const int MAXN = 2e5 + 10; vector<int> g[MAXN]; vector<int> c[MAXN]; int n; void read() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; x--; c[x].push_back(i); } for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } } int tin[MAXN], timer = 0; int tout[MAXN]; int sz[MAXN]; const int MAXLOG = 20; int dp[MAXN][MAXLOG]; int help_sum[MAXN]; int get(int n) { if (n < 0) return 0; return n * (n - 1) / 2 + n; } void dfs(int v, int p) { tin[v] = timer++; sz[v] = 1; dp[v][0] = p; for (int i = 1; i < MAXLOG; i++) dp[v][i] = dp[dp[v][i - 1]][i - 1]; for (auto i : g[v]) { if (i == p) continue; dfs(i, v); help_sum[v] += get(sz[i]); sz[v] += sz[i]; } tout[v] = timer; } bool is_upper(int v, int u) { return tin[v] <= tin[u] && tout[v] >= tout[u]; } int lca(int v, int u) { if (is_upper(v, u)) return v; if (is_upper(u, v)) return u; for (int i = MAXLOG - 1; i >= 0; i--) if (!is_upper(dp[v][i], u)) v = dp[v][i]; return dp[v][0]; } int pre_lca(int p, int v) { for (int i = MAXLOG - 1; i >= 0; i--) if (!is_upper(dp[v][i], p)) v = dp[v][i]; return v; } int ans[MAXN]; vector<int> get_all_vert(vector<int> &v) { sort(all(v), [&](int a, int b) { return tin[a] < tin[b]; }); v.resize(unique(all(v)) - v.begin()); vector<int> have = v; int n = v.size(); for (int i = 0; i < n - 1; i++) { have.push_back(lca(have[i], have[i + 1])); } sort(all(have), [&](int a, int b) { return tin[a] < tin[b]; }); have.resize(unique(all(have)) - have.begin()); return have; } vector<vector<int>> build_tree(vector<int> &have) { int n = have.size(); vector<vector<int>> tree(n); vector<pair<int, int>> st; for (int i = 0; i < n; i++) { while (!st.empty() && !is_upper(st.back().first, have[i])) st.pop_back(); if (!st.empty()) { tree[st.back().second].push_back(i); } st.push_back({have[i], i}); } return tree; } bool cmp(int a, int b) { return tin[a] < tin[b]; } int dfs_calc(int v, vector<vector<int>> &g, vector<int> &have, vector<int> &good, int &fans) { bool flag = false; int pos = lower_bound(all(good), have[v], cmp) - good.begin(); if (pos >= 0 && pos < (int)good.size() && good[pos] == have[v]) { flag = true; } int cnt = 0; if (flag) { cnt = sz[have[v]]; } int other = help_sum[have[v]]; for (auto i : g[v]) { int now = dfs_calc(i, g, have, good, fans); if (flag) { int x = get(sz[pre_lca(have[v], have[i])] - now); fans += x; other -= get(sz[pre_lca(have[v], have[i])]); } else { cnt += now; } } if (flag) { fans += other; } return cnt; } int calc(vector<int> v) { if (v.empty()) return get(n); vector<int> have = get_all_vert(v); /*cout << "have = " << endl; for (auto i : have) { cout << i << " "; } cout << endl;*/ vector<vector<int>> g = build_tree(have); /*cout << "g = " << endl; for (auto i : g) { for (auto j : i) { cout << j << " "; } cout << endl; }*/ int ans = 0; int now = dfs_calc(0, g, have, v, ans); // cout << "ans = " << ans << endl; // cout << now << endl; ans += get(sz[0] - now); return ans; } void run() { dfs(0, 0); // cout << get(n) - calc(c[0]) << endl; // exit(0); for (int i = 0; i < n; i++) { ans[i] = get(n) - calc(c[i]); } // cout << "puhh" << endl; } void write() { for (int i = 0; i < n; i++) cout << ans[i] << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read(); run(); write(); return 0; } /* WA 128 input = 6 1 2 1 1 3 1 1 2 2 3 1 4 1 5 2 6 ans = 13 0 0 6 0 19 out = 13 0 0 6 0 20 */
replace
17
18
17
18
0
p02710
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long struct ss { int node, nxt; } e[600005]; inline int read() { int re = 0, k = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') k = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { re = (re << 1) + (re << 3) + ch - 48; ch = getchar(); } return re * k; } int u, v, n, col[100005], f[100005], del[100005], s[100005], sz[100005], head[100005], tot, g[100005]; void add(int u, int v) { e[++tot].nxt = head[u]; e[tot].node = v; head[u] = tot; } void getsz(int x, int fa) { for (int i = head[x]; i; i = e[i].nxt) { int t = e[i].node; if (t == fa) continue; getsz(t, x); sz[x] += sz[t]; } } void dfs(int x, int fa) { int lst = s[col[fa]]; s[col[fa]] = x; if (s[col[x]]) del[s[col[x]]] += sz[x]; else g[col[x]] += sz[x]; for (int i = head[x]; i; i = e[i].nxt) { int t = e[i].node; if (t == fa) continue; dfs(t, x); } int now = sz[x] - del[x]; // cerr<<col[fa]<<" "<<now<<" "<<sz[x]<<endl; f[col[fa]] += now * (now + 1) >> 1; s[col[fa]] = lst; } signed main() { n = read(); for (int i = 1; i <= n; i++) { col[i] = read(); sz[i] = 1; } for (int i = 1; i <= n - 1; i++) { u = read(); v = read(); add(u, v); add(v, u); } getsz(1, 0); dfs(1, 0); for (int i = 1; i <= n; i++) g[i] = (n - g[i]) * (n - g[i] + 1) >> 1; int ans = n * (n + 1) >> 1; for (int i = 1; i <= n; i++) { printf("%lld\n", ans - f[i] - g[i]); } }
#include <bits/stdc++.h> using namespace std; #define int long long struct ss { int node, nxt; } e[600005]; inline int read() { int re = 0, k = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') k = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { re = (re << 1) + (re << 3) + ch - 48; ch = getchar(); } return re * k; } int u, v, n, col[200005], f[200005], del[200005], s[200005], sz[200005], head[200005], tot, g[200005]; void add(int u, int v) { e[++tot].nxt = head[u]; e[tot].node = v; head[u] = tot; } void getsz(int x, int fa) { for (int i = head[x]; i; i = e[i].nxt) { int t = e[i].node; if (t == fa) continue; getsz(t, x); sz[x] += sz[t]; } } void dfs(int x, int fa) { int lst = s[col[fa]]; s[col[fa]] = x; if (s[col[x]]) del[s[col[x]]] += sz[x]; else g[col[x]] += sz[x]; for (int i = head[x]; i; i = e[i].nxt) { int t = e[i].node; if (t == fa) continue; dfs(t, x); } int now = sz[x] - del[x]; // cerr<<col[fa]<<" "<<now<<" "<<sz[x]<<endl; f[col[fa]] += now * (now + 1) >> 1; s[col[fa]] = lst; } signed main() { n = read(); for (int i = 1; i <= n; i++) { col[i] = read(); sz[i] = 1; } for (int i = 1; i <= n - 1; i++) { u = read(); v = read(); add(u, v); add(v, u); } getsz(1, 0); dfs(1, 0); for (int i = 1; i <= n; i++) g[i] = (n - g[i]) * (n - g[i] + 1) >> 1; int ans = n * (n + 1) >> 1; for (int i = 1; i <= n; i++) { printf("%lld\n", ans - f[i] - g[i]); } }
replace
20
22
20
22
0
p02710
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << endl #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int c[N]; for (int i = 0; i < N; i++) cin >> c[i], c[i]--; vector<vector<int>> graph(N); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; graph[a].push_back(b); graph[b].push_back(a); } int sz[N]; fill(sz, sz + N, 1); long long ans[N]; fill(ans, ans + N, (long long)N * (N + 1) / 2); map<int, int> mp[N]; auto merge = [](map<int, int> &A, map<int, int> &B) { if (A.size() < B.size()) swap(A, B); for (auto &p : B) A[p.first] += p.second; return A; }; function<void(int, int)> dfs = [&](int v, int p) { for (int ch : graph[v]) if (ch != p) { dfs(ch, v); sz[v] += sz[ch]; mp[v] = merge(mp[v], mp[ch]); } mp[v][c[v]] = sz[v]; if (p != -1) { long long tmp = sz[v] - mp[v][c[p]]; ans[c[p]] -= tmp * (tmp + 1) / 2; } }; dfs(0, -1); for (int i = 0; i < N; i++) { long long tmp = N - mp[0][i]; ans[i] -= tmp * (tmp + 1) / 2; } for (int i = 0; i < N; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } #ifdef __LOCAL #define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl #define debugArray(x, n) \ cerr << __LINE__ << ": " << #x << " = {"; \ for (long long hoge = 0; (hoge) < (n); ++(hoge)) \ cerr << ((hoge) ? "," : "") << x[hoge]; \ cerr << "}" << endl #else #define debug(x) (void(0)) #define debugArray(x, n) (void(0)) #endif signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int c[N]; for (int i = 0; i < N; i++) cin >> c[i], c[i]--; vector<vector<int>> graph(N); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; graph[a].push_back(b); graph[b].push_back(a); } int sz[N]; fill(sz, sz + N, 1); long long ans[N]; fill(ans, ans + N, (long long)N * (N + 1) / 2); map<int, int> mp[N]; auto merge = [](map<int, int> &A, map<int, int> &B) { if (A.size() < B.size()) swap(A, B); for (auto &p : B) A[p.first] += p.second; return A; }; function<void(int, int)> dfs = [&](int v, int p) { for (int ch : graph[v]) if (ch != p) { dfs(ch, v); sz[v] += sz[ch]; if (mp[v].size() < mp[ch].size()) swap(mp[v], mp[ch]); for (auto &p : mp[ch]) mp[v][p.first] += p.second; } mp[v][c[v]] = sz[v]; if (p != -1) { long long tmp = sz[v] - mp[v][c[p]]; ans[c[p]] -= tmp * (tmp + 1) / 2; } }; dfs(0, -1); for (int i = 0; i < N; i++) { long long tmp = N - mp[0][i]; ans[i] -= tmp * (tmp + 1) / 2; } for (int i = 0; i < N; i++) cout << ans[i] << endl; return 0; }
replace
52
53
52
56
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes" << endl; return 0; } n /= 10; } cout << "No" << endl; }
insert
11
11
11
12
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { char n[2]; cin >> n; if (n[0] == '7' || n[1] == '7' || n[2] == '7') 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; using ll = long long; using P = pair<int, int>; int main() { char n[3]; cin >> n; if (n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes" << endl; else cout << "No" << endl; return 0; }
replace
7
8
7
8
-6
*** stack smashing detected ***: terminated
p02711
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <vector> typedef long long int ll; // #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { if (t % 10 == 7) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <time.h> #include <vector> typedef long long int ll; // #include<bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t) { if (t % 10 == 7) { cout << "Yes" << endl; return 0; } t /= 10; } cout << "No" << endl; return 0; }
insert
31
31
31
32
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; // #define in freopen("in.txt","r",stdin) // #define out freopen("out.txt","w",stdout) #define N 1e9 + 10; ll n, m, i, j, k, t, l, r; ll a, b, c, d; char A, C, X, Y, Z; ll ans, MAX, MIN, sum; ll ax[2000500]; char cx[500]; ll dx[12]; ll bx[500]; int main() { t = 1; // scanf("%lld",&t); while (t--) { cin >> n; int flag = 0; while (n / 10) { if (n % 10 == 7) { flag = 1; break; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; // #define in freopen("in.txt","r",stdin) // #define out freopen("out.txt","w",stdout) #define N 1e9 + 10; ll n, m, i, j, k, t, l, r; ll a, b, c, d; char A, C, X, Y, Z; ll ans, MAX, MIN, sum; ll ax[2000500]; char cx[500]; ll dx[12]; ll bx[500]; int main() { t = 1; // scanf("%lld",&t); while (t--) { cin >> n; int flag = 0; if (n % 10 == 7) flag = 1; n = n / 10; if (n % 10 == 7) flag = 1; n = n / 10; if (n % 10 == 7) flag = 1; if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
replace
21
27
21
29
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(1) == '7' || s.at(2) == '7' || s.at(3) == '7') cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7') cout << "Yes" << endl; else cout << "No" << endl; }
replace
6
7
6
7
0
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string N; for (int i = 0; i < 3; i++) { if (N.at(i) == 7) { cout << "Yes" << endl; break; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; if (N[0] == '7' || N[1] == '7' || N[2] == '7') { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
5
12
5
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02711
C++
Runtime Error
/* Coded and Decoded by : Yash Kapoor */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define mp make_pair #define pll pair<ll, ll> #define vl vector<ll> #define sl set<ll> #define vll vector<pll> #define ml map<ll, ll> #define mll map<pll, ll> #define all(a) a.begin(), a.end() #define x first #define y second #define sz(x) (ll) x.size() #define dl '\n' // #define why (ll)1000000007 #define why (ll)998244353 #define lp(i, a, b) for (ll i = a; i < b; ++i) #define lpr(i, a, b) for (ll i = a; i >= b; i--) #define lpd(i, x) for (auto i : x) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll inf = 1e18; ld pi = 3.141592653589; ll mod = why; ll fast_power(ll base, ll power, ll mod) { ll result = 1; while (power) { if (power % 2) result = (result * base) % mod; base = (base * base) % mod; power /= 2; } return result; } ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); } ll solve() { string a; cin >> a; lp(i, 0, sz(a)) if (a[i] == '7') { cout << "Yes"; return 0; } cout << "No"; } int main() { ios ll t = 1; // cin>>t; while (t--) { solve(); } }
/* Coded and Decoded by : Yash Kapoor */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define mp make_pair #define pll pair<ll, ll> #define vl vector<ll> #define sl set<ll> #define vll vector<pll> #define ml map<ll, ll> #define mll map<pll, ll> #define all(a) a.begin(), a.end() #define x first #define y second #define sz(x) (ll) x.size() #define dl '\n' // #define why (ll)1000000007 #define why (ll)998244353 #define lp(i, a, b) for (ll i = a; i < b; ++i) #define lpr(i, a, b) for (ll i = a; i >= b; i--) #define lpd(i, x) for (auto i : x) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); ll inf = 1e18; ld pi = 3.141592653589; ll mod = why; ll fast_power(ll base, ll power, ll mod) { ll result = 1; while (power) { if (power % 2) result = (result * base) % mod; base = (base * base) % mod; power /= 2; } return result; } ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); } ll solve() { string a; cin >> a; lp(i, 0, sz(a)) if (a[i] == '7') { cout << "Yes"; return 0; } cout << "No"; return 0; } int main() { ios ll t = 1; // cin>>t; while (t--) { solve(); } }
insert
57
57
57
58
0
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> #define PI 3.14159265358979323846264338327950L #define ll long long using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n > 0) { int digit = n % 10; if (digit == 7) { cout << "Yes" << "\n"; return 0; } } cout << "No" << "\n"; }
#include <bits/stdc++.h> #include <math.h> #define PI 3.14159265358979323846264338327950L #define ll long long using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; while (n > 0) { int digit = n % 10; if (digit == 7) { cout << "Yes" << "\n"; return 0; } n = n / 10; } cout << "No" << "\n"; }
insert
20
20
20
21
TLE
p02711
C++
Time Limit Exceeded
// In the name of GOD #include <bits/stdc++.h> #define ll long long #define pp pair<int, int> using namespace std; const int N = 1e5 + 10; string s; int n; void solve() { cin >> n; while (n > 0) { if (n % 10 == 7) { cout << "Yes"; return; } } cout << "No"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt = 1; // cin >> tt; for (int tc = 1; tc <= tt; ++tc) { solve(); } }
// In the name of GOD #include <bits/stdc++.h> #define ll long long #define pp pair<int, int> using namespace std; const int N = 1e5 + 10; string s; int n; void solve() { cin >> n; while (n > 0) { if (n % 10 == 7) { cout << "Yes"; return; } n /= 10; } cout << "No"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt = 1; // cin >> tt; for (int tc = 1; tc <= tt; ++tc) { solve(); } }
insert
17
17
17
18
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ll; const ll INF = 1000000009; void solve() { int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes\n"; return; } } cout << "No\n"; } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); #endif // int t;cin >> t;while(t--) solve(); solve(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ll; const ll INF = 1000000009; void solve() { int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes\n"; return; } n /= 10; } cout << "No\n"; } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); #endif // int t;cin >> t;while(t--) solve(); solve(); }
insert
14
14
14
15
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n; for (int i = n; i >= 0; i = i / 10) { if (i % 10 == 7) { cout << "Yes" << endl; c = 1; break; } else c = 0; } if (c == 0) cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, c; cin >> n; for (int i = n; i > 0; i = i / 10) { if (i % 10 == 7) { cout << "Yes" << endl; c = 1; break; } else c = 0; } if (c == 0) cout << "No" << endl; }
replace
5
6
5
6
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define Hello \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define endl '\n' int main() { Hello int n; cin >> n; while (n) { if (n % 10 == 7) return cout << "Yes", 01; n /= 10; } cout << "No"; return 0; }
#include <bits/stdc++.h> using namespace std; #define Hello \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define endl '\n' int main() { Hello int n; cin >> n; while (n) { if (n % 10 == 7) return cout << "Yes", 0; n /= 10; } cout << "No"; return 0; }
replace
13
14
13
14
1
p02711
Python
Runtime Error
N = int(input()) str(N) listN = sorted(N) if listN.count("7") >= 1: print("Yes") else: print("No")
N = int(input()) listN = sorted(str(N)) if listN.count("7") >= 1: print("Yes") else: print("No")
replace
1
3
1
2
TypeError: 'int' object is not iterable
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02711/Python/s383379366.py", line 3, in <module> listN = sorted(N) TypeError: 'int' object is not iterable
p02711
Python
Runtime Error
N = input() ans = "No" for i in range(len(N)): if N[i] == 7: global ans ans = "Yes" break else: continue print(ans)
N = int(input()) a1 = N % 10 a2 = ((N % 100) - a1) / 10 a3 = N // 100 if a1 == 7 or a2 == 7 or a3 == 7: print("Yes") else: print("No")
replace
0
10
0
8
SyntaxError: name 'ans' is assigned to before global declaration
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02711/Python/s548817950.py", line 5 global ans ^^^^^^^^^^ SyntaxError: name 'ans' is assigned to before global declaration
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { char s[3]; int i; for (i = 0; i < 3; i++) { cin >> s[i]; } for (i = 0; i < 3; i++) { if (s[i] == '7') { cout << "Yes" << endl; exit(1); } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[3]; int i; for (i = 0; i < 3; i++) { cin >> s[i]; } for (i = 0; i < 3; i++) { if (s[i] == '7') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
replace
13
14
13
14
1
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; int solve() { int d_1 = n % 10; int d_10 = (n - d_1) % 100 / 10; int d_100 = (n - d_1 - d_10) % 1000 / 100; if (d_1 == 7 || d_10 == 7 || d_100 == 7) cout << "Yes"; else cout << "No"; } int main() { cin >> n; solve(); return EXIT_SUCCESS; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; void solve() { int d_1 = n % 10; int d_10 = (n - d_1) % 100 / 10; int d_100 = (n - d_1 - d_10) % 1000 / 100; if (d_1 == 7 || d_10 == 7 || d_100 == 7) cout << "Yes"; else cout << "No"; } int main() { cin >> n; solve(); return EXIT_SUCCESS; }
replace
7
8
7
8
0
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int r; while (n > 0) { r = n % 10; if (r == 7) { break; } } if (n) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int r; while (n > 0) { r = n % 10; if (r == 7) { break; } n /= 10; } if (n) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
insert
18
18
18
19
TLE
p02711
C++
Time Limit Exceeded
#include <iostream> #include <set> #include <string> #include <vector> using namespace std; int main(void) { long long K, count = 0; cin >> K; while (K != 0) { if (K % 10 == 7) { cout << "Yes\n"; return 0; } K %= 10; } cout << "No\n"; }
#include <iostream> #include <set> #include <string> #include <vector> using namespace std; int main(void) { long long K, count = 0; cin >> K; while (K != 0) { if (K % 10 == 7) { cout << "Yes\n"; return 0; } K /= 10; } cout << "No\n"; }
replace
15
16
15
16
TLE
p02711
Python
Runtime Error
N = input() print("Yes" if 7 in N else "No")
N = input() print("Yes" if "7" in N else "No")
replace
1
2
1
2
TypeError: 'in <string>' requires string as left operand, not int
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02711/Python/s754651467.py", line 2, in <module> print('Yes' if 7 in N else 'No') TypeError: 'in <string>' requires string as left operand, not int
p02711
C++
Time Limit Exceeded
// Problem : A - Lucky 7 // Contest : AtCoder Beginner Contest 162 // URL : https://atcoder.jp/contests/abc162/tasks/abc162_a // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n != 0) { if (n % 10 == 7) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
// Problem : A - Lucky 7 // Contest : AtCoder Beginner Contest 162 // URL : https://atcoder.jp/contests/abc162/tasks/abc162_a // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n != 0) { if (n % 10 == 7) { cout << "Yes" << endl; return 0; } n = n / 10; } cout << "No" << endl; return 0; }
insert
21
21
21
22
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i; bool p = true; while (p) { if (n % 10 == 7) { cout << "Yes"; p = false; } n = n / 10; } if (p) cout << "No"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int i; bool p = true; while (p) { if (n % 10 == 7) { cout << "Yes"; p = false; } n = n / 10; if (n == 0) break; } if (p) cout << "No"; return 0; }
insert
13
13
13
15
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; if (N.at(1) == '7' || N.at(2) == '7' || N.at(3) == '7') { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; if (N[0] == '7' || N[1] == '7' || N[2] == '7') { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
6
8
6
7
0
p02711
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define ll long long using namespace std; void isN(int n) { while (n) { if (n % 10 == 7) { cout << "Yes\n"; return; } } cout << "No\n"; return; } int main() { int T; cin >> T; isN(T); return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> #define ll long long using namespace std; void isN(int n) { while (n) { if (n % 10 == 7) { cout << "Yes\n"; return; } n /= 10; } cout << "No\n"; return; } int main() { int T; cin >> T; isN(T); return 0; }
insert
12
12
12
13
TLE
p02711
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { char n[3]; for (int i = 1; i < 4; i++) { cin >> n[i]; if (n[i] == '7') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; int a, b, c; a = n / 100; b = n / 10 - a * 10; c = n % 10; if (a == 7 || b == 7 || c == 7) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
replace
20
29
20
33
-6
*** stack smashing detected ***: terminated
p02711
C++
Time Limit Exceeded
// #include<bits/stdc++.h> // using namespace std; // const int N = 1000000000, MAXI = N, D = 14; // int main() { // freopen("output.txt", "r", stdin); // freopen("input.txt", "w", stdout); // srand(time(nullptr)); // int tc = 5, flag = 1; // cout << tc << "\n"; // while (tc--) // { // int a = rand()%N+1; // a *= flag; // flag *= -1; // int b = rand()%MAXI + 1, c; // int d = rand()%D + 1; // int flag2 = rand()%3, k; // if(flag2==0) // { // k = rand()%d+1; // c = a + k*b; // } // else if(flag2==1) // { // k = rand()%d + 1; // c = a - k*b; // } // else // c = rand()%MAXI; // cout << a << " " << b << " " << c << " " << d; // cout << "\n"; // cout << "~\n"; // } // return 0; // } //---------------------------------------------// /* #define int long long #define mod (int)(1e9+9) #define endl '\n' #define MAXI (int)(3e17+10) #define N 200005 */ // /* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 9) #define endl '\n' #define MAXI (int)(3e17 + 10) #define N 200005 // Driver code to test above functions int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes"; return 0; } } cout << "No"; return 0; }
// #include<bits/stdc++.h> // using namespace std; // const int N = 1000000000, MAXI = N, D = 14; // int main() { // freopen("output.txt", "r", stdin); // freopen("input.txt", "w", stdout); // srand(time(nullptr)); // int tc = 5, flag = 1; // cout << tc << "\n"; // while (tc--) // { // int a = rand()%N+1; // a *= flag; // flag *= -1; // int b = rand()%MAXI + 1, c; // int d = rand()%D + 1; // int flag2 = rand()%3, k; // if(flag2==0) // { // k = rand()%d+1; // c = a + k*b; // } // else if(flag2==1) // { // k = rand()%d + 1; // c = a - k*b; // } // else // c = rand()%MAXI; // cout << a << " " << b << " " << c << " " << d; // cout << "\n"; // cout << "~\n"; // } // return 0; // } //---------------------------------------------// /* #define int long long #define mod (int)(1e9+9) #define endl '\n' #define MAXI (int)(3e17+10) #define N 200005 */ // /* while(!cin.eof()) */ #include <bits/stdc++.h> using namespace std; #define int long long #define mod (int)(1e9 + 9) #define endl '\n' #define MAXI (int)(3e17 + 10) #define N 200005 // Driver code to test above functions int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes"; return 0; } n /= 10; } cout << "No"; return 0; }
insert
79
79
79
80
TLE
p02711
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define endl '\n' #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef long double ld; typedef pair<int, string> P; typedef tuple<int, string, string> T; typedef complex<double> comp; typedef vector<vector<ld>> matrix; struct pairhash { public: template <typename T, typename U> size_t operator()(const pair<T, U> &x) const { size_t seed = hash<T>()(x.first); return hash<U>()(x.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; const int inf = 1e9 + 9; const ll mod = 1e9 + 7; const double eps = 1e-8; const double pi = acos(-1); int n; bool solve() { while (n > 0) { if (n % 10 == 7) return true; } return false; } void input() { cin >> n; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); input(); cout << (solve() ? "Yes" : "No") << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string.h> #include <string> #include <sys/time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define endl '\n' #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end()) typedef long long ll; typedef long double ld; typedef pair<int, string> P; typedef tuple<int, string, string> T; typedef complex<double> comp; typedef vector<vector<ld>> matrix; struct pairhash { public: template <typename T, typename U> size_t operator()(const pair<T, U> &x) const { size_t seed = hash<T>()(x.first); return hash<U>()(x.second) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } }; const int inf = 1e9 + 9; const ll mod = 1e9 + 7; const double eps = 1e-8; const double pi = acos(-1); int n; bool solve() { while (n > 0) { if (n % 10 == 7) return true; n /= 10; } return false; } void input() { cin >> n; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); input(); cout << (solve() ? "Yes" : "No") << endl; }
insert
53
53
53
54
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int a, c = 0; cin >> a; while (a) { if (a % 10 == 7) { cout << "Yes\n"; return 0; } } cout << "No\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int a, c = 0; cin >> a; while (a) { if (a % 10 == 7) { cout << "Yes\n"; return 0; } a /= 10; } cout << "No\n"; }
insert
11
11
11
12
TLE
p02711
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> using namespace std; using ll = long long; int main() { string N = 0; cin >> N; for (int i = 0; i < 3; i++) { if (N[i] == '7') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> using namespace std; using ll = long long; int main() { string N; cin >> N; for (int i = 0; i < 3; i++) { if (N[i] == '7') { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::logic_error' what(): basic_string: construction from null is not valid
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define ff first #define ss second #define mod 1000000007 int32_t main() { IO; int n; cin >> n; bool f = false; while (n > 0) { int x = n % 10; if (x == 7) { f = true; break; } x /= 10; } if (f) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define ff first #define ss second #define mod 1000000007 int32_t main() { IO; int n; cin >> n; bool f = false; while (n > 0) { int x = n % 10; if (x == 7) { f = true; break; } n /= 10; } if (f) cout << "Yes"; else cout << "No"; return 0; }
replace
23
24
23
24
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, tmp; cin >> N; bool flg = true; while (N > 0) { tmp = N % 10; if (tmp == 7) { cout << "Yes" << endl; flg = false; break; } } if (flg == true) { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, tmp; cin >> N; bool flg = true; while (N > 0) { tmp = N % 10; N /= 10; if (tmp == 7) { cout << "Yes" << endl; flg = false; break; } } if (flg == true) { cout << "No" << endl; } }
insert
10
10
10
11
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; if (N.at(1) != '7' && N.at(2) != '7' && N.at(3) != '7') cout << "No" << endl; else cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; if (N.at(0) != '7' && N.at(1) != '7' && N.at(2) != '7') cout << "No" << endl; else cout << "Yes" << endl; }
replace
6
7
6
7
0
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { int s; cin >> s; ll c = 0; while (s > 0) { if (s % 10 == 7) { c = 1; break; } c = c / 10; } if (c == 1) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { int s; cin >> s; ll c = 0; while (s > 0) { if (s % 10 == 7) { c = 1; break; } s = s / 10; } if (c == 1) cout << "Yes" << endl; else cout << "No" << endl; }
replace
12
13
12
13
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a) ? "Yes" : "No") typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INFLL = 1LL << 62; const int INF = 1 << 30; const double PI = acos(-1); int main() { string n; int ans = 0; scanf("%s", &n); // cin >>n; cout << solve(n[0] == '7' || n[1] == '7' || n[2] == '7') << endl; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define pb push_back #define solve(a) ((a) ? "Yes" : "No") typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long INFLL = 1LL << 62; const int INF = 1 << 30; const double PI = acos(-1); int main() { string n; int ans = 0; cin >> n; cout << solve(n[0] == '7' || n[1] == '7' || n[2] == '7') << endl; }
replace
37
39
37
39
-11
p02711
C++
Time Limit Exceeded
/// Bismillahir Rahmanir Rahim #include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define f0(n) for (int i = 0; i < n; i++) #define ms(x) memset(x, 0, sizeof(x)) #define ins insert #define ALL(v) v.begin(), v.end() #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define PI acos(-1) #define IOS ios::sync_with_stdio(false); using namespace std; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const long long MOD = 1000000007; template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } int main() { IOS int n; cin >> n; while (n > 1) { if (n % 10 == 7) { cout << "Yes\n"; return 0; } } cout << "No\n"; return 0; } /// Alhamdulillah
/// Bismillahir Rahmanir Rahim #include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define f0(n) for (int i = 0; i < n; i++) #define ms(x) memset(x, 0, sizeof(x)) #define ins insert #define ALL(v) v.begin(), v.end() #define highest(x) numeric_limits<x>::max() #define lowest(x) numeric_limits<x>::min() #define Inf INFINITY #define minv(v) *min_element(v.begin(), v.end()) #define maxv(v) *max_element(v.begin(), v.end()) #define PI acos(-1) #define IOS ios::sync_with_stdio(false); using namespace std; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; const long long MOD = 1000000007; template <typename T> inline T Bigmod(T base, T power, T MOD) { T ret = 1; while (power) { if (power & 1) ret = (ret * base) % MOD; base = (base * base) % MOD; power >>= 1; } return ret; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } int main() { IOS int n; cin >> n; while (n > 1) { if (n % 10 == 7) { cout << "Yes\n"; return 0; } n /= 10; } cout << "No\n"; return 0; } /// Alhamdulillah
insert
45
45
45
46
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; if (n.at(1) != '7' && n.at(2) != '7' && n.at(3) != '7') { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; if (n.at(1) != '7' && n.at(2) != '7' && n.at(0) != '7') { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
5
6
5
6
0
p02711
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long #define pb push_back #define all(a) (a).begin(), (a).end() #define pii pair<int, int> #define ld long double ostream &operator<<(ostream &a, const vector<int> &b) { for (auto k : b) cout << k << " "; return a; } #ifdef LOCAL #define dbg(x) cout << #x << " : " << (x) << "\n"; const int INF = 1e18; // const int mod = 2600000069; // const int p = 10; // const ld PI = 3.1415926535; #else #define dbg(x) const int INF = 1e18; // const int mod = 2600000069; // const int p = 179; // const ld PI = 3.1415926535; #endif // #pragma GCC optimize("Ofast,no-stack-protector") // #pragma GCC target("sse,sse2,sse3,sse3,sse4") // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("fast-math") // #pragma GCC target("avx2") // #pragma GCC optimize("section-anchors") // #pragma GCC optimize("profile-values,profile-reorder-functions,tracer") // #pragma GCC optimize("vpt") // #pragma GCC optimize("rename-registers") // #pragma GCC optimize("move-loop-invariants") // #pragma GCC optimize("unswitch-loops") // #pragma GCC optimize("function-sections") // #pragma GCC optimize("data-sections") signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes\n"; return 0; } } cout << "No\n"; //---------------------------------------------------------------------- #ifdef LOCAL cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n"; #endif } /* */
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <istream> #include <map> #include <ostream> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long #define pb push_back #define all(a) (a).begin(), (a).end() #define pii pair<int, int> #define ld long double ostream &operator<<(ostream &a, const vector<int> &b) { for (auto k : b) cout << k << " "; return a; } #ifdef LOCAL #define dbg(x) cout << #x << " : " << (x) << "\n"; const int INF = 1e18; // const int mod = 2600000069; // const int p = 10; // const ld PI = 3.1415926535; #else #define dbg(x) const int INF = 1e18; // const int mod = 2600000069; // const int p = 179; // const ld PI = 3.1415926535; #endif // #pragma GCC optimize("Ofast,no-stack-protector") // #pragma GCC target("sse,sse2,sse3,sse3,sse4") // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("fast-math") // #pragma GCC target("avx2") // #pragma GCC optimize("section-anchors") // #pragma GCC optimize("profile-values,profile-reorder-functions,tracer") // #pragma GCC optimize("vpt") // #pragma GCC optimize("rename-registers") // #pragma GCC optimize("move-loop-invariants") // #pragma GCC optimize("unswitch-loops") // #pragma GCC optimize("function-sections") // #pragma GCC optimize("data-sections") signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; while (n) { if (n % 10 == 7) { cout << "Yes\n"; return 0; } n /= 10; } cout << "No\n"; //---------------------------------------------------------------------- #ifdef LOCAL cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n"; #endif } /* */
insert
75
75
75
76
TLE
p02711
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = getchar(); } while ('0' <= _c && _c <= '9') { x = (x << 1) + (x << 3) + (_c & 15); _c = getchar(); } if (_f) x = -x; } template <typename T> inline void Min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void Max(T &x, T y) { if (x < y) x = y; } #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define pb push_back const int INF = 0x3f3f3f3f; const double pi = (double)acos(-1.0); const double eps = (double)1e-8; // const int MOD = (int) 1e9 + 7; // const int MOD = (int) 998244353; int MOD = 998244353; const int e5 = (int)1e5 + 5; const int maxn = (int)1e5 + 20; const int maxm = (int)1e6 + 20; inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL mod = MOD) { if (n < 0) a = fp(a, mod - 2, mod), n = -n; LL res = 1; for (; n; n >>= 1, a = a * a % mod) if (n & 1) res = res * a % mod; return res; } struct Mint { LL x; Mint() { x = 0; } Mint(int _x) : x(_x) {} Mint(LL _x) : x(_x) {} Mint operator-() const { return Mint(MOD - x); } Mint operator+(const Mint &rhs) const { LL res = x + rhs.x; if (res >= MOD) res -= MOD; return Mint(res); } Mint operator-(const Mint &rhs) const { LL res = x - rhs.x; if (res < 0) res += MOD; return Mint(res); } Mint operator*(const Mint &rhs) const { return Mint(x * rhs.x % MOD); } Mint operator/(const Mint &rhs) const { return Mint(x * fp(rhs.x, -1) % MOD); } Mint &operator+=(const Mint &rhs) { x += rhs.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator*=(const Mint &rhs) { x = (x * rhs.x) % MOD; return *this; } bool operator==(const Mint &rhs) const { return x == rhs.x; } bool operator!=(const Mint &rhs) const { return x != rhs.x; } friend ostream &operator<<(ostream &out, const Mint &rhs) { return out << rhs.x; } friend istream &operator>>(istream &in, Mint &rhs) { return in >> rhs.x; } }; void work() { int x; read(x); while (x) { if (x % 10 == 7) { cout << "Yes"; return; } x /= 10; } cout << "No"; } int main(int argc, char **argv) { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 // get_prime(); // pre(); int tc = 1; read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); work(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define LL long long typedef pair<int, int> pii; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = getchar(); } while ('0' <= _c && _c <= '9') { x = (x << 1) + (x << 3) + (_c & 15); _c = getchar(); } if (_f) x = -x; } template <typename T> inline void Min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void Max(T &x, T y) { if (x < y) x = y; } #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define pb push_back const int INF = 0x3f3f3f3f; const double pi = (double)acos(-1.0); const double eps = (double)1e-8; // const int MOD = (int) 1e9 + 7; // const int MOD = (int) 998244353; int MOD = 998244353; const int e5 = (int)1e5 + 5; const int maxn = (int)1e5 + 20; const int maxm = (int)1e6 + 20; inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL mod = MOD) { if (n < 0) a = fp(a, mod - 2, mod), n = -n; LL res = 1; for (; n; n >>= 1, a = a * a % mod) if (n & 1) res = res * a % mod; return res; } struct Mint { LL x; Mint() { x = 0; } Mint(int _x) : x(_x) {} Mint(LL _x) : x(_x) {} Mint operator-() const { return Mint(MOD - x); } Mint operator+(const Mint &rhs) const { LL res = x + rhs.x; if (res >= MOD) res -= MOD; return Mint(res); } Mint operator-(const Mint &rhs) const { LL res = x - rhs.x; if (res < 0) res += MOD; return Mint(res); } Mint operator*(const Mint &rhs) const { return Mint(x * rhs.x % MOD); } Mint operator/(const Mint &rhs) const { return Mint(x * fp(rhs.x, -1) % MOD); } Mint &operator+=(const Mint &rhs) { x += rhs.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator*=(const Mint &rhs) { x = (x * rhs.x) % MOD; return *this; } bool operator==(const Mint &rhs) const { return x == rhs.x; } bool operator!=(const Mint &rhs) const { return x != rhs.x; } friend ostream &operator<<(ostream &out, const Mint &rhs) { return out << rhs.x; } friend istream &operator>>(istream &in, Mint &rhs) { return in >> rhs.x; } }; void work() { int x; read(x); while (x) { if (x % 10 == 7) { cout << "Yes"; return; } x /= 10; } cout << "No"; } int main(int argc, char **argv) { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 // get_prime(); // pre(); int tc = 1; // read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); work(); } return 0; }
replace
130
131
130
131
TLE
p02711
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { char str1[2]; cin >> str1[2]; if (str1[0] == '7' || str1[1] == '7' || str1[2] == '7') cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; bool ans = false; cin >> s; for (int i = 0; i < 3; i++) { if (s[i] == '7') { ans = true; } } if (ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
replace
4
7
4
13
-6
*** stack smashing detected ***: terminated
p02711
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int num, check = 7, count, temp; while (cin >> num, num >= 100 && num < 1000) { count = 0; while (num > 0) { temp = num % 10; if (temp == check) { count++; if (count != 0) { cout << "Yes" << endl; } break; } num /= 10; } if (count == 0) { cout << "No" << endl; break; } } }
#include <iostream> using namespace std; int main() { int num, check = 7, count, temp; while (cin >> num, num >= 100 && num < 1000) { count = 0; while (num > 0) { temp = num % 10; if (temp == check) { count++; if (count != 0) { cout << "Yes" << endl; } break; } num /= 10; } if (count == 0) { cout << "No" << endl; break; } break; } }
insert
21
21
21
22
TLE
p02712
C++
Time Limit Exceeded
#include <stdio.h> int main() { // jika 3 dan 5 membagi == fixxbuzz // jika dibagi 3 doang ==fizz // jika dibagi 5 doang == buzz // jika ttidak a =i // pakai long long int katanya warning overflow? long long int n, sum = 0; scanf("%d", &n); for (int i = 0; i < n; i++) { if (i % 3 == 0 || i % 5 == 0) { continue; } else { sum += i; } } printf("%lld", sum); return 0; }
#include <stdio.h> int main() { long long int max, sum = 0; scanf("%lld", &max); for (int i = 0; i <= max; i++) { if (i % 3 != 0 && i % 5 != 0) { sum = sum + i; } } printf("%lld", sum); return 0; }
replace
3
15
3
8
TLE
p02712
C++
Time Limit Exceeded
#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 signed main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { if (i % 3 == 0) i = 0; if (i % 5 == 0) i = 0; sum += i; } cout << sum << 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 signed main() { int n; cin >> n; int sum = 0; for (int i = 1; i <= n; i++) { int b = i; if (b % 3 == 0) b = 0; else if (b % 5 == 0) b = 0; sum += b; } cout << sum << endl; }
replace
35
40
35
41
TLE
p02712
C++
Runtime Error
#include <cstdio> using namespace std; typedef long long ll; int main() { int n; ll sum = 0; scanf("%lld", &n); for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) sum += i; } printf("%lld", sum); }
#include <cstdio> using namespace std; typedef long long ll; int main() { int n; ll sum = 0; scanf("%d", &n); for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) sum += i; } printf("%lld", sum); }
replace
8
9
8
9
0
p02712
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int N; cin >> N; long long ans = 0; int i; for (i = 1; 1 <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { ans += i; } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N; cin >> N; long long ans = 0; int i; for (i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) { ans += i; } } cout << ans << endl; }
replace
7
8
7
8
TLE
p02712
Python
Runtime Error
N = int(input().split()) print(sum([n + 1 for n in range(N) if (n + 1) % 3 != 0 and (n + 1) % 5 != 0]))
N = int(input()) print(sum([n + 1 for n in range(N) if (n + 1) % 3 != 0 and (n + 1) % 5 != 0]))
replace
0
1
0
1
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02712/Python/s624885598.py", line 1, in <module> N = int(input().split()) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
p02712
C++
Time Limit Exceeded
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <unordered_set> #include <utility> #include <vector> #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define pf printf #define ff first #define ss second #define sef second.first #define ses second.second #define ms(a, b) memset(a, b, sizeof(a)) #define loop(i, a) for (int i = 1; i <= a; i++) #define pii pair<int, int> #define sl(a) scanf("%I64d", &a) #define sll(a, b) scanf("%I64d %I64d", &a, &b) #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d %d", &a, &b) using namespace std; typedef long long ll; const int maxx = 8e4 + 10; // typedef pair < int , pii > node ; // node tree[4*maxx],lazy[4*maxx]; int tree[4 * maxx], lazy[4 * maxx]; int main() { ll n, sum = 0, i = 1, k = 0; sl(n); loop(i, n) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } cout << sum << endl; return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <set> #include <stdio.h> #include <unordered_set> #include <utility> #include <vector> #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define pf printf #define ff first #define ss second #define sef second.first #define ses second.second #define ms(a, b) memset(a, b, sizeof(a)) #define loop(i, a) for (int i = 1; i <= a; i++) #define pii pair<int, int> #define sl(a) scanf("%I64d", &a) #define sll(a, b) scanf("%I64d %I64d", &a, &b) #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d %d", &a, &b) using namespace std; typedef long long ll; const int maxx = 8e4 + 10; // typedef pair < int , pii > node ; // node tree[4*maxx],lazy[4*maxx]; int tree[4 * maxx], lazy[4 * maxx]; int main() { long long sum = 0, n; cin >> n; for (int i = 1; i <= n; i++) { if (i % 3 != 0 && i % 5 != 0) { sum += i; } } cout << sum << endl; return 0; }
replace
30
33
30
33
TLE
p02712
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n; long long sum = 0, s[100000]; cin >> n; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) s[i] = 0; else s[i] = i; } for (int i = 1; i <= n; i++) sum += s[i]; cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, s[1000009]; long long sum = 0; cin >> n; for (int i = 1; i <= n; i++) { if (i % 3 == 0 || i % 5 == 0) s[i] = 0; else s[i] = i; } for (int i = 1; i <= n; i++) sum += s[i]; cout << sum << endl; }
replace
3
5
3
5
0
p02712
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long sum(int n) { return (long)n * (n + 1) / 2; } int main() { int n; scanf("%ld", &n); printf("%ld\n", sum(n) - sum(n / 3) * 3 - sum(n / 5) * 5 + sum(n / 15) * 15); }
#include <bits/stdc++.h> using namespace std; long sum(int n) { return (long)n * (n + 1) / 2; } int main() { int n; scanf("%d", &n); printf("%ld\n", sum(n) - sum(n / 3) * 3 - sum(n / 5) * 5 + sum(n / 15) * 15); }
replace
7
8
7
8
-6
*** stack smashing detected ***: terminated
p02712
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long N; scanf("%ld", N); long ans = 0; for (long i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) ans += i; } printf("%ld", ans); }
#include <bits/stdc++.h> using namespace std; int main() { long N; scanf("%ld", &N); long ans = 0; for (long i = 1; i <= N; i++) { if (i % 3 != 0 && i % 5 != 0) ans += i; } printf("%ld", ans); }
replace
5
6
5
6
-11
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } int gcd(int a, int b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { gcd(b, a - b); } } int gcd(int a, int b, int c) { int d = gcd(a, b); return gcd(d, c); } int main() { int k; cin >> k; int sum = 0; for (int a = 1; a <= k; a++) { for (int b = 1; b <= k; b++) { for (int c = 1; c <= k; c++) { sum += gcd(a, b, c); } } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } int gcd(int a, int b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd(b, a - b); } } int gcd(int a, int b, int c) { int d = gcd(a, b); return gcd(d, c); } int main() { int k; cin >> k; int sum = 0; for (int a = 1; a <= k; a++) { for (int b = 1; b <= k; b++) { for (int c = 1; c <= k; c++) { sum += gcd(a, b, c); } } } cout << sum << endl; return 0; }
replace
25
26
25
26
0
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int gcd(int, int); vector<int> waru(vector<int>); int main() { int K; int sum = 0; cin >> K; for (int a = 1; a <= K; a++) { for (int b = 1; b <= K; b++) { for (int c = 1; c <= K; c++) { sum += gcd(gcd(a, b), c); } } } cout << sum << endl; } int gcd(int a, int b) { vector<int> vec = {a, b}; while (vec.at(1) != 0) { vec = waru(vec); } return vec.at(0); } vector<int> waru(vector<int> i) { vector<int> vec(2); int syou; vec.at(0) = i.at(1); syou = i.at(0) / i.at(1); vec.at(1) = i.at(0) - syou * i.at(1); return vec; }
#include <bits/stdc++.h> using namespace std; int gcd(int, int); vector<int> waru(vector<int>); int main() { int K; int sum = 0; cin >> K; for (int a = 1; a <= K; a++) { for (int b = 1; b <= K; b++) { for (int c = 1; c <= K; c++) { sum += gcd(gcd(a, b), c); } } } cout << sum << endl; } int gcd(int a, int b) { vector<int> vec = {a, b}; if (a < b) swap(vec.at(0), vec.at(1)); while (vec.at(1) != 0) { vec = waru(vec); } return vec.at(0); } vector<int> waru(vector<int> i) { vector<int> vec(2); int syou; vec.at(0) = i.at(1); syou = i.at(0) / i.at(1); vec.at(1) = i.at(0) - syou * i.at(1); return vec; }
insert
21
21
21
23
TLE
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { if (!(p % q)) return q; else return gcd(q, p % q); } int main() { int k; cin >> k; int sum = 0; for (int a = 0; a < k; a++) { for (int b = 0; b < k; b++) { for (int c = 0; c < k; c++) { sum += gcd(gcd(a, b), c); } } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { if (!(p % q)) return q; else return gcd(q, p % q); } int main() { int k; cin >> k; int sum = 0; for (int a = 1; a <= k; a++) { for (int b = 1; b <= k; b++) { for (int c = 1; c <= k; c++) { sum += gcd(gcd(a, b), c); } } } cout << sum << endl; }
replace
14
17
14
17
-8
p02713
C++
Runtime Error
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int gcd(int p, int q) { if (p % q == 0) return q; return gcd(q, p % q); } int main() { int k; cin >> k; int sum = 0; rep(h, k) { rep(i, k) { rep(j, k) { sum += gcd(h, gcd(i, j)); } } } cout << sum << endl; }
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int gcd(int p, int q) { if (p % q == 0) return q; return gcd(q, p % q); } int main() { int k; cin >> k; int sum = 0; for (int h = 1; h <= k; h++) { for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { sum += gcd(h, gcd(i, j)); } } } cout << sum << endl; }
replace
16
19
16
21
-8
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int x = 0, s = 0; for (int l = 1; l <= k; l++) { for (int m = 1; m <= k; m++) { for (int n = 1; n <= k; n++) { for (int i = 1; i <= max(l, max(m, n)); i++) { if (l % i == 0 && m % i == 0 && n % i == 0) { x = i; } } s += x; x = 0; } } } cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int k; cin >> k; int x = 0, s = 0; for (int l = 1; l <= k; l++) { for (int m = 1; m <= k; m++) { for (int n = 1; n <= k; n++) { for (int i = 1; i <= min(l, min(m, n)); i++) { if (l % i == 0 && m % i == 0 && n % i == 0) { x = i; } } s += x; x = 0; } } } cout << s << endl; }
replace
10
11
10
11
TLE
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <string> using namespace std; typedef long long ll; typedef long double ld; int MOD = 1000000007; ll gcd(ll N, ll M, ll L) { while (M != N) if (M > N) M = M - N; else N = N - M; while (M != L) if (M > L) M = M - L; else L = L - M; } int main() { ll K, sum = 0; cin >> K; for (ll i = 1; i <= K; i++) { for (ll j = 1; j <= K; j++) { for (ll k = 1; k <= K; k++) { sum += gcd(i, j, k); } } } cout << sum << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <iomanip> #include <iostream> #include <string> using namespace std; typedef long long ll; typedef long double ld; int MOD = 1000000007; ll gcd(ll N, ll M, ll L) { while (M != N) if (M > N) M = M - N; else N = N - M; while (M != L) if (M > L) M = M - L; else L = L - M; return L; } int main() { ll K, sum = 0; cin >> K; for (ll i = 1; i <= K; i++) { for (ll j = 1; j <= K; j++) { for (ll k = 1; k <= K; k++) { sum += gcd(i, j, k); } } } cout << sum << endl; }
insert
24
24
24
26
TLE
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #define il inline #define re register #define fo(i, j, k) for (register int i = j; i <= k; i++) #define do(i, j, k) for (register int i = j; i >= k; i--) #define inf 0x7fffffff typedef long long ll; using namespace std; il ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f * x; } /*int h[200010],v[200010],dis[200010]; struct edge { int v,w,next; }e[200010*2]; il void add(int u,int v,int w) { e[++cnt].v=v; e[cnt].w=w; e[cnt].next=h[u]; h[u]=cnt; }*/ ll n, k, ans; ll dp[100010]; const ll mod = 1e9 + 7; ll cal(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1LL; } return ret; } int main() { // easy n = read(), k = read(); for (re ll i = k; i >= 1; i--) { ll num = k / i; dp[i] = cal(num, n); for (ll j = 2 * i; j <= k; j += i) { dp[i] = (dp[i] - dp[j] + mod) % mod; } ans = (ans + dp[i] * i) % mod; } printf("%lld\n", ans); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #define il inline #define re register #define fo(i, j, k) for (register int i = j; i <= k; i++) #define do(i, j, k) for (register int i = j; i >= k; i--) #define inf 0x7fffffff typedef long long ll; using namespace std; il ll read() { ll x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f * x; } /*int h[200010],v[200010],dis[200010]; struct edge { int v,w,next; }e[200010*2]; il void add(int u,int v,int w) { e[++cnt].v=v; e[cnt].w=w; e[cnt].next=h[u]; h[u]=cnt; }*/ ll n, k, ans; ll dp[100010]; const ll mod = 1e9 + 7; ll cal(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = (ret * a) % mod; a = (a * a) % mod; b >>= 1LL; } return ret; } int main() { // easy n = 3, k = read(); for (re ll i = k; i >= 1; i--) { ll num = k / i; dp[i] = cal(num, n); for (ll j = 2 * i; j <= k; j += i) { dp[i] = (dp[i] - dp[j] + mod) % mod; } ans = (ans + dp[i] * i) % mod; } printf("%lld\n", ans); }
replace
53
54
53
54
TLE
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int k, min_; int sum = 0, mul = 1; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int i1 = i; int j1 = j; int l1 = l; mul = 1; for (int m = 2; m <= k;) { if (i1 % m == 0 && j1 % m == 0 && l1 % m == 0) { mul = mul * m; i1 = i1 / m; j1 = j1 / m; l1 = l1 / m; } else m++; // if( i1 < m ) break; } sum += mul; } } } cout << sum << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int k, min_; int sum = 0, mul = 1; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int i1 = i; int j1 = j; int l1 = l; mul = 1; for (int m = 2; m <= k;) { if (i1 % m == 0 && j1 % m == 0 && l1 % m == 0) { mul = mul * m; i1 = i1 / m; j1 = j1 / m; l1 = l1 / m; } else m++; if (i1 < m) break; } sum += mul; } } } cout << sum << endl; return 0; }
replace
25
26
25
27
TLE
p02713
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.141592653589793 // vector < vector<int>>a(0, vector<int>(0));二次元配列宣言 int main() { long long int sum = 0; int i, j, h, g; int k; cin >> k; for (i = 1; i <= k; i++) { for (j = 1; j <= k; j++) { for (h = 1; h <= k; h++) { for (g = max(max(i, j), max(j, h)); g >= 1; g--) { if (i % g == 0 && j % g == 0 && h % g == 0) { sum += g; break; } } } } } cout << sum << endl; }
#include "bits/stdc++.h" using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.141592653589793 // vector < vector<int>>a(0, vector<int>(0));二次元配列宣言 int main() { long long int sum = 0; int i, j, h, g; int k; cin >> k; for (i = 1; i <= k; i++) { for (j = 1; j <= k; j++) { for (h = 1; h <= k; h++) { for (g = min(min(i, j), min(j, h)); g >= 1; g--) { if (i % g == 0 && j % g == 0 && h % g == 0) { sum += g; break; } } } } } cout << sum << endl; }
replace
14
15
14
15
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int s = 0, a, b, c; long long sum = 0; int gcd(int a, int b, int c) { for (int i = a; i >= 1; i--) { if (a % i == 0 && b % i == 0 && c % i == 0) { s = i; break; } } return s; } int main() { int k; cin >> k; for (a = 1; a <= k; a++) { for (b = 1; b <= k; b++) { for (c = 1; c <= k; c++) { sum += gcd(a, b, c); } } } cout << sum; return 0; }
#include <bits/stdc++.h> using namespace std; int s = 0, a, b, c; long long sum = 0; int gcd(int a, int b, int c) { for (int i = a; i >= 1; i--) { if (a % i == 0 && b % i == 0 && c % i == 0) { s = i; break; } } return s; } int main() { int k; cin >> k; for (a = 1; a <= k; a++) { for (b = a; b <= k; b++) { for (c = b; c <= k; c++) { if (a == b && b == c) sum += gcd(a, b, c); else if (a == b || b == c || c == a) sum += 3 * gcd(a, b, c); else sum += 6 * gcd(a, b, c); } } } cout << sum; return 0; }
replace
17
20
17
25
TLE
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { int a = min(x, y); int b = 0; for (int i = 0; i < a + 1; i++) { if (x % i == 0 && y % i == 0) { b = i; } } return b; } int main() { int K; cin >> K; int ans = 0; for (int i = 0; i < K; i++) { for (int j = 0; j < K; j++) { for (int k = 0; k < K; k++) { ans += gcd(gcd(i + 1, j + 1), k + 1); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { int a = min(x, y); int b = 0; for (int i = 0; i < a; i++) { if (x % (i + 1) == 0 && y % (i + 1) == 0) { b = i + 1; } } return b; } int main() { int K; cin >> K; int ans = 0; for (int i = 0; i < K; i++) { for (int j = 0; j < K; j++) { for (int k = 0; k < K; k++) { ans += gcd(gcd(i + 1, j + 1), k + 1); } } } cout << ans << endl; }
replace
6
9
6
9
-8
p02713
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { long K; cin >> K; long sum = 0; for (int a = 1; a < K + 1; a++) { for (int b = 1; b < K + 1; b++) { for (int c = 1; c < K + 1; c++) { int gcd = 0; for (int i = 1; i < c + 1; i++) { if (a % i == 0 && b % i == 0 && c % i == 0) { gcd = i; } } sum = sum + gcd; } } } cout << sum << endl; return 0; }
#include <iostream> using namespace std; int main() { long K; cin >> K; long sum = 0; for (int a = 1; a < K + 1; a++) { for (int b = 1; b < K + 1; b++) { for (int c = 1; c < K + 1; c++) { int gcd = 0; for (int i = 1; i < a + 1 && i < b + 1 && i < c + 1; i++) { if (a % i == 0 && b % i == 0 && c % i == 0) { gcd = i; } } sum = sum + gcd; } } } cout << sum << endl; return 0; }
replace
10
11
10
11
TLE
p02713
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; int kansuu(int a, int b) { int tempa = max(a, b); int tempb = min(a, b); if (tempa % tempb == 0) { return tempb; } else { kansuu(tempb, tempa % tempb); } } int gcd(int a, int b, int c) { return kansuu(kansuu(a, b), c); } int main() { int k; cin >> k; int ans = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { ans += gcd(i, j, l); } } } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; int kansuu(int a, int b) { int tempa = max(a, b); int tempb = min(a, b); if (tempa % tempb == 0) { return tempb; } else { return kansuu(tempb, tempa % tempb); } } int gcd(int a, int b, int c) { return kansuu(kansuu(a, b), c); } int main() { int k; cin >> k; int ans = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { ans += gcd(i, j, l); } } } cout << ans << endl; }
replace
9
10
9
10
0
p02713
C++
Runtime Error
#include <iostream> using namespace std; int gcd2(int a, int b) { int c, max = 0; max = b; if (max < a) { max = a; a = b; b = max; } c = b % a; if (c == 0) { return a; } else { gcd2(a, c); } } int gcd3(int a, int b, int c) { int x, y; x = gcd2(a, b); y = gcd2(x, c); return y; } int main(void) { int k, ans = 0; cin >> k; for (int i = 1; i <= k; i++) { for (int s = 1; s <= k; s++) { for (int t = 1; t <= k; t++) { ans = ans + gcd3(i, s, t); } } } cout << ans << "\n"; return 0; }
#include <iostream> using namespace std; int gcd2(int a, int b) { int c, max = 0; max = b; if (max < a) { max = a; a = b; b = max; } c = b % a; if (c == 0) { return a; } else { return gcd2(a, c); } } int gcd3(int a, int b, int c) { int x, y; x = gcd2(a, b); y = gcd2(x, c); return y; } int main(void) { int k, ans = 0; cin >> k; for (int i = 1; i <= k; i++) { for (int s = 1; s <= k; s++) { for (int t = 1; t <= k; t++) { ans = ans + gcd3(i, s, t); } } } cout << ans << "\n"; return 0; }
replace
15
16
15
16
0
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int main() { int k, min_; int sum = 0, mul = 1; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int i1 = i; int j1 = j; int l1 = l; mul = 1; for (int m = 2; m <= max(max(i1, j1), l1);) { if (i1 % m == 0 && j1 % m == 0 && l1 % m == 0) { mul = mul * m; i1 = i1 / m; j1 = j1 / m; l1 = l1 / m; } else m++; // if( i1 < m || j1 < m || l1 < m ) break; // // この工夫がないとACされない } sum += mul; } } } cout << sum << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int k, min_; int sum = 0, mul = 1; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int i1 = i; int j1 = j; int l1 = l; mul = 1; for (int m = 2; m <= max(max(i1, j1), l1);) { if (i1 % m == 0 && j1 % m == 0 && l1 % m == 0) { mul = mul * m; i1 = i1 / m; j1 = j1 / m; l1 = l1 / m; } else m++; if (i1 < m || j1 < m || l1 < m) break; // この工夫がないとACされない } sum += mul; } } } cout << sum << endl; return 0; }
replace
25
27
25
27
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int K; int gcd(int a, int b, int c) { for (int d = K; d > 0; d--) { if (a % d == 0 and b % d == 0 and c % d == 0) { return d; } } } int main() { int ans = 0; cin >> K; for (int a = 1; a < K + 1; a++) { for (int b = 1; b < K + 1; b++) { for (int c = 1; c < K + 1; c++) { ans += gcd(a, b, c); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int K; int gcd(int a, int b, int c) { for (int d = c; d > 0; d--) { if (a % d == 0 and b % d == 0 and c % d == 0) { return d; } } } int main() { int ans = 0; cin >> K; for (int a = 1; a < K + 1; a++) { for (int b = 1; b < K + 1; b++) { for (int c = 1; c < K + 1; c++) { ans += gcd(a, b, c); } } } cout << ans << endl; }
replace
6
7
6
7
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { freopen("input.txt", "r", stdin); int n; cin >> n; long long int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { int temp = __gcd(i, j); sum += __gcd(temp, k); } } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // freopen ("input.txt", "r", stdin); int n; cin >> n; long long int sum = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { int temp = __gcd(i, j); sum += __gcd(temp, k); } } } cout << sum << endl; return 0; }
replace
6
7
6
7
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (n); i++) typedef pair<int, int> P; const int INF = 100000000; int gcd(int a, int b, int c) { int min_num = min(a, min(b, c)); int base; for (int i = 1; min_num + 1; i++) { if (min_num % i == 0) { base = min_num / i; } if ((a % base == 0) && (b % base == 0) && (c % base == 0)) { return base; } } return 0; } int main() { int K; cin >> K; int ans = 0; rep(i, K) { rep(j, K) { rep(k, K) { ans += gcd(i + 1, j + 1, k + 1); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (n); i++) typedef pair<int, int> P; const int INF = 100000000; int gcd(int a, int b, int c) { int min_num = min(a, min(b, c)); int base; for (int i = 1; min_num + 1; i++) { if (min_num % i == 0) { base = min_num / i; } if ((a % base == 0) && (b % base == 0) && (c % base == 0)) { return base; } } return 0; } int main() { int K; cin >> K; int ans = 0; for (int i = 1; i <= K; i++) { for (int j = i; j <= K; j++) { for (int k = j; k <= K; k++) { if (i == j && j == k) { ans += gcd(i, j, k); } else if (i != j && j != k && k != i) { ans += gcd(i, j, k) * 6; } else { ans += gcd(i, j, k) * 3; } } } } cout << ans << endl; }
replace
26
29
26
37
TLE
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> int gcd(int a, int b, int c) { for (int i = std::max(a, std::max(b, c)); i > 1; i--) { if (a % i == 0 && b % i == 0 && c % i == 0) return i; } return 1; } int main() { int n; long long res = 0; std::cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { res += gcd(i, j, k); } } } std::cout << res << std::endl; return 0; }
#include <algorithm> #include <iostream> int gcd(int a, int b, int c) { for (int i = std::min(a, std::min(b, c)); i > 1; i--) { if (a % i == 0 && b % i == 0 && c % i == 0) return i; } return 1; } int main() { int n; long long res = 0; std::cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { res += gcd(i, j, k); } } } std::cout << res << std::endl; return 0; }
replace
5
6
5
6
TLE
p02713
C++
Runtime Error
// Sum of gcd of Tuples (Easy) #include <algorithm> #include <complex> #include <deque> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long; using P = pair<int, int>; int gcd(int p, int q) { if (p % q == 0) return q; return gcd(q, p % q); } int main() { int K; cin >> K; int sum = 0; for (int i = 1; i <= K; i++) { for (int j = 0; j <= K; j++) { for (int k = 0; k <= K; k++) { int tmp = gcd(j, k); sum += gcd(i, tmp); } } } cout << sum << endl; return 0; }
// Sum of gcd of Tuples (Easy) #include <algorithm> #include <complex> #include <deque> #include <iostream> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) using namespace std; using ll = long long; using P = pair<int, int>; int gcd(int p, int q) { if (p % q == 0) return q; return gcd(q, p % q); } int main() { int K; cin >> K; int sum = 0; for (int i = 1; i <= K; i++) { for (int j = 1; j <= K; j++) { for (int k = 1; k <= K; k++) { int tmp = gcd(j, k); sum += gcd(i, tmp); } } } cout << sum << endl; return 0; }
replace
27
29
27
29
-8
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll get(ll x, ll y) { ll res = 1ll; while (y) { if (y & 1) { res = (res * x) % MOD; } y >>= 1; x = (x * x) % MOD; } return res; } void solve() { int n, k; n = 3; cin >> k; vector<ll> cur(n + 1); for (int i = 1; i <= k; i++) { cur[i] = get((k / i), n); } for (int i = k; i >= 1; i--) { for (int j = i + i; j <= k; j += i) { cur[i] -= cur[j]; cur[i] %= MOD; if (cur[i] < 0) cur[i] += MOD; } } ll ans = 0; for (ll i = 1; i <= k; i++) { // cout << cur[i] << '\n'; ans = (ans + i * cur[i]) % MOD; } cout << ans << '\n'; } int main() { int t; t = 1; for (int cs = 1; cs <= t; cs++) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll get(ll x, ll y) { ll res = 1ll; while (y) { if (y & 1) { res = (res * x) % MOD; } y >>= 1; x = (x * x) % MOD; } return res; } void solve() { int n, k; n = 3; cin >> k; vector<ll> cur(k + 1); for (int i = 1; i <= k; i++) { cur[i] = get((k / i), n); } for (int i = k; i >= 1; i--) { for (int j = i + i; j <= k; j += i) { cur[i] -= cur[j]; cur[i] %= MOD; if (cur[i] < 0) cur[i] += MOD; } } ll ans = 0; for (ll i = 1; i <= k; i++) { // cout << cur[i] << '\n'; ans = (ans + i * cur[i]) % MOD; } cout << ans << '\n'; } int main() { int t; t = 1; for (int cs = 1; cs <= t; cs++) { solve(); } }
replace
24
25
24
25
0
p02713
C++
Runtime Error
/* include */ #include "bits/stdc++.h" /* namespace */ using namespace std; /* typedef */ /* long系 */ typedef long long ll; // long long typedef long double ld; // long double /* vector系 */ typedef vector<int> vint; // intのvector typedef vector<double> vdouble; // doubleのvector typedef vector<ll> vll; // llのvector typedef vector<ld> vld; // ldのvector typedef vector<pair<int, int>> vi_i; // i_iのvector typedef vector<pair<double, double>> vd_d; // d_dのvector typedef vector<pair<ll, ll>> vl_l; // l_lのvector typedef vector<pair<ld, ld>> vld_ld; // ld_ldのvector typedef vector<string> vstring; // stringのvector /* pair系 */ typedef pair<int, int> i_i; // int同士のpair typedef pair<double, double> d_d; // double同士のpair typedef pair<ll, ll> l_l; // ll同士のpair typedef pair<ld, ld> ld_ld; // ld同士のpair /* define */ #define pb push_back // push_back #define all(v) v.begin(), v.end() // コンテナ全体 #define PI (acos(-1)) // 円周率pi /* 変数入出力 read, write */ template <typename T> // 1変数 void read(T &x) { cin >> x; } template <typename T, typename T0> // 2変数 void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> // 3変数 void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> // 4変数 void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } template <typename T> // 1変数 void write(T &x) { cout << x << endl; } template <typename T, typename T0> // 2変数 void write(T &x, T0 &y) { cout << x << " " << y << endl; } template <typename T, typename T0, typename T1> // 3変数 void write(T &x, T0 &y, T1 &z) { cout << x << " " << y << " " << z << endl; } template <typename T, typename T0, typename T1, typename T2> // 4変数 void write(T &x, T0 &y, T1 &z, T2 &w) { cout << x << " " << y << " " << z << " " << w << endl; } // vectorの出力 template <typename T> void printvec(const vector<T> &data) { for (const auto elm : data) { cout << elm << " "; } cout << endl; } // 最大公約数 ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { gcd(b, a % b); } } int main(void) { ll k; read(k); ll ans = 0; for (ll i = 1; i <= k; i++) { for (ll j = 1; j <= k; j++) { for (ll l = 1; l <= k; l++) { ll reg = gcd(i, j); reg = gcd(reg, l); ans += reg; } } } write(ans); return 0; }
/* include */ #include "bits/stdc++.h" /* namespace */ using namespace std; /* typedef */ /* long系 */ typedef long long ll; // long long typedef long double ld; // long double /* vector系 */ typedef vector<int> vint; // intのvector typedef vector<double> vdouble; // doubleのvector typedef vector<ll> vll; // llのvector typedef vector<ld> vld; // ldのvector typedef vector<pair<int, int>> vi_i; // i_iのvector typedef vector<pair<double, double>> vd_d; // d_dのvector typedef vector<pair<ll, ll>> vl_l; // l_lのvector typedef vector<pair<ld, ld>> vld_ld; // ld_ldのvector typedef vector<string> vstring; // stringのvector /* pair系 */ typedef pair<int, int> i_i; // int同士のpair typedef pair<double, double> d_d; // double同士のpair typedef pair<ll, ll> l_l; // ll同士のpair typedef pair<ld, ld> ld_ld; // ld同士のpair /* define */ #define pb push_back // push_back #define all(v) v.begin(), v.end() // コンテナ全体 #define PI (acos(-1)) // 円周率pi /* 変数入出力 read, write */ template <typename T> // 1変数 void read(T &x) { cin >> x; } template <typename T, typename T0> // 2変数 void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> // 3変数 void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> // 4変数 void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } template <typename T> // 1変数 void write(T &x) { cout << x << endl; } template <typename T, typename T0> // 2変数 void write(T &x, T0 &y) { cout << x << " " << y << endl; } template <typename T, typename T0, typename T1> // 3変数 void write(T &x, T0 &y, T1 &z) { cout << x << " " << y << " " << z << endl; } template <typename T, typename T0, typename T1, typename T2> // 4変数 void write(T &x, T0 &y, T1 &z, T2 &w) { cout << x << " " << y << " " << z << " " << w << endl; } // vectorの出力 template <typename T> void printvec(const vector<T> &data) { for (const auto elm : data) { cout << elm << " "; } cout << endl; } // 最大公約数 ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main(void) { ll k; read(k); ll ans = 0; for (ll i = 1; i <= k; i++) { for (ll j = 1; j <= k; j++) { for (ll l = 1; l <= k; l++) { ll reg = gcd(i, j); reg = gcd(reg, l); ans += reg; } } } write(ans); return 0; }
replace
76
77
76
77
0
p02713
C++
Runtime Error
#include <iostream> using namespace std; const int N = 210; int dp[N][N]; int gcd(int a, int b) { if (dp[a][b]) return dp[a][b]; if (dp[b][a]) { dp[a][b] = dp[b][a]; return dp[a][b]; } else { int aaaa = gcd(b, a - a / b * b); dp[a][b] = aaaa; dp[b][a] = aaaa; return aaaa; } } int main() { int k; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= i; j++) { gcd(i, j); } } long long res = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int m = 1; m <= k; m++) { res += dp[dp[i][j]][dp[j][m]]; } } } cout << res; }
#include <iostream> using namespace std; const int N = 210; int dp[N][N]; int gcd(int a, int b) { if (dp[a][b]) return dp[a][b]; if (dp[b][a]) { dp[a][b] = dp[b][a]; return dp[a][b]; } else { if (a % b == 0) { dp[a][b] = b; dp[b][a] = b; return b; } else { int aaaa = gcd(b, a - (a / b) * b); dp[a][b] = aaaa; dp[b][a] = aaaa; return aaaa; } } } int main() { int k; cin >> k; for (int i = 1; i <= k; i++) { for (int j = 1; j <= i; j++) { gcd(i, j); } } long long res = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int m = 1; m <= k; m++) { res += dp[dp[i][j]][dp[j][m]]; } } } cout << res; }
replace
13
17
13
23
-8
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { if (p % q == 0) return q; else gcd(q, p % q); } int main() { int N; cin >> N; int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { sum += gcd(gcd(i + 1, j + 1), k + 1); } } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int p, int q) { if (p % q == 0) return q; else return gcd(q, p % q); } int main() { int N; cin >> N; int sum = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { for (int k = 0; k < N; k++) { sum += gcd(gcd(i + 1, j + 1), k + 1); } } } cout << sum << endl; }
replace
7
8
7
8
0
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; ll sum = 0; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; i <= n; j++) { int gcd = __gcd(i, j); for (int k = 1; k <= n; k++) { sum += __gcd(gcd, k); } } } cout << sum; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; ll sum = 0; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int gcd = __gcd(i, j); for (int k = 1; k <= n; k++) { sum += __gcd(gcd, k); } } } cout << sum; }
replace
11
12
11
12
TLE
p02713
C++
Runtime Error
#include <iostream> using namespace std; int gcd(int b, int c) { while (b % c == 0) { int a = b % c; b = c; c = a; } return c; } int main() { int n; cin >> n; long long int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { ans += gcd(i, gcd(j, k)); } } } cout << ans << endl; }
#include <iostream> using namespace std; int gcd(int b, int c) { while (b % c != 0) { int a = b % c; b = c; c = a; } return c; } int main() { int n; cin >> n; long long int ans = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { for (int k = 1; k <= n; k++) { ans += gcd(i, gcd(j, k)); } } } cout << ans << endl; }
replace
3
4
3
4
-8
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <stdio.h> #define debug(x) cout << '>' << #x << ':' << x << endl; #define nitro ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); const int INF = 1e9 + 5; using namespace std; using ll = unsigned long long int; const ll mod = 998244353; int main() { // your code goes here freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int k; cin >> k; ll total = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int temp = __gcd(j, l); total += __gcd(i, temp); } } } cout << total; }
#include <bits/stdc++.h> #include <stdio.h> #define debug(x) cout << '>' << #x << ':' << x << endl; #define nitro ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); const int INF = 1e9 + 5; using namespace std; using ll = unsigned long long int; const ll mod = 998244353; int main() { // your code goes here // freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); int k; cin >> k; ll total = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { for (int l = 1; l <= k; l++) { int temp = __gcd(j, l); total += __gcd(i, temp); } } } cout << total; }
replace
12
14
12
13
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; ll ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int k = 1; k <= n; ++k) { ans += __gcd(k, __gcd(i, j)); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; ll ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { for (int k = 1; k <= n; ++k) { ans += __gcd(k, __gcd(i, j)); } } } cout << ans << endl; }
replace
6
7
6
7
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int e_gcd(int a, int b) { if (a < b) return e_gcd(b, a); int r = 0; while (r == a % b) { a = b; b = r; } return b; } int gcd(int a, int b, int c) { return e_gcd(e_gcd(a, b), c); } int main() { int k; cin >> k; long long sum = 0; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= k; ++j) { for (int l = 1; l <= k; ++l) { sum += gcd(i, j, l); } } } cout << sum; }
#include <bits/stdc++.h> using namespace std; int e_gcd(int a, int b) { if (a < b) return e_gcd(b, a); int r; while ((r = a % b)) { a = b; b = r; } return b; } int gcd(int a, int b, int c) { return e_gcd(e_gcd(a, b), c); } int main() { int k; cin >> k; long long sum = 0; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= k; ++j) { for (int l = 1; l <= k; ++l) { sum += gcd(i, j, l); } } } cout << sum; }
replace
6
8
6
8
TLE
p02713
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) < 0 ? (-(a)) : (a)) typedef long long ll; using namespace std; int get_gcd(int a, int b) { while (b) { int temp = b; b = a % b; a = temp; } return a; } int main() { freopen("input.txt", "r", stdin); ios::sync_with_stdio(false); cin.tie(NULL); int K; ll sum = 0; scanf("%d", &K); for (int i = 1; i <= K; ++i) { for (int j = 1; j <= K; ++j) { for (int k = 1; k <= K; ++k) sum += get_gcd(get_gcd(i, j), k); } } printf("%lld\n", sum); return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <vector> #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define ABS(a) ((a) < 0 ? (-(a)) : (a)) typedef long long ll; using namespace std; int get_gcd(int a, int b) { while (b) { int temp = b; b = a % b; a = temp; } return a; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int K; ll sum = 0; scanf("%d", &K); for (int i = 1; i <= K; ++i) { for (int j = 1; j <= K; ++j) { for (int k = 1; k <= K; ++k) sum += get_gcd(get_gcd(i, j), k); } } printf("%lld\n", sum); return 0; }
delete
31
33
31
31
TLE
p02713
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> using namespace std; #define ll long long ll gcd(ll a, ll b) { while (b) b ^= a ^= b ^= a %= b; } int main() { ll n, ans = 0; scanf("%lld", &n); ll c[n + 1]; fill(c, c + n + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { c[gcd(i, j)]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans += gcd(i, j) * c[j]; } } printf("%lld\n", ans); }
#include <algorithm> #include <cstdio> using namespace std; #define ll long long ll gcd(ll a, ll b) { while (b) b ^= a ^= b ^= a %= b; return a; } int main() { ll n, ans = 0; scanf("%lld", &n); ll c[n + 1]; fill(c, c + n + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { c[gcd(i, j)]++; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { ans += gcd(i, j) * c[j]; } } printf("%lld\n", ans); }
insert
7
7
7
8
TLE
p02713
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { int K; cin >> K; int sum = 0; for (int a = 1; a <= K; a++) { for (int b = 1; b <= K; b++) { for (int c = 1; c <= K; c++) { for (int d = (max(max(a, b), c)); d >= 1; d--) { if (a % d == 0 && b % d == 0 && c % d == 0) { sum += d; break; } } } } } cout << sum << endl; }
#include <iostream> using namespace std; int main() { int K; cin >> K; int sum = 0; for (int a = 1; a <= K; a++) { for (int b = 1; b <= K; b++) { for (int c = 1; c <= K; c++) { for (int d = (min(min(a, b), c)); d >= 1; d--) { if (a % d == 0 && b % d == 0 && c % d == 0) { sum += d; break; } } } } } cout << sum << endl; }
replace
11
12
11
12
TLE
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int gcd(int x, int y) { if (x < y) swap(x, y); while (true) { if (x % y == 0) break; x = y; y = x % y; } return y; } int main() { int K; cin >> K; int sum = 0; int s = 0; for (int i = 1; i <= K; i++) { for (int j = 1; j <= K; j++) { for (int k = 1; k <= K; k++) { s = gcd(i, j); sum += gcd(s, k); } } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int K; cin >> K; int sum = 0; int s = 0; for (int i = 1; i <= K; i++) { for (int j = 1; j <= K; j++) { for (int k = 1; k <= K; k++) { s = gcd(i, j); sum += gcd(s, k); } } } cout << sum << endl; }
replace
3
13
3
8
0
p02713
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int gcd(int a, int b) { if (a < b) swap(a, b); if (a % b == 0) return b; else gcd(b, a % b); } int gcd3(int a, int b, int c) { int g = gcd(a, b); return gcd(g, c); } int main() { int K; cin >> K; long long sum = 0; for (int a = 1; a <= K; ++a) { for (int b = 1; b <= K; ++b) { for (int c = 1; c <= K; ++c) { sum += gcd3(a, b, c); } } } cout << sum << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; int gcd(int x, int y) { if (x < y) { swap(x, y); // 小さい方をyとする } int r = x % y; while (r != 0) { x = y; y = r; r = x % y; } return y; } int gcd3(int a, int b, int c) { int g = gcd(a, b); return gcd(g, c); } int main() { int K; cin >> K; long long sum = 0; for (int a = 1; a <= K; ++a) { for (int b = 1; b <= K; ++b) { for (int c = 1; c <= K; ++c) { sum += gcd3(a, b, c); } } } cout << sum << endl; return 0; }
replace
8
15
8
19
0
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define froop1(a, n) for (long long i = a; i < n; i++) #define froop2(a, n) for (int i = a; i > n; i--) int main() { long long N, sum = 0; cin >> N; froop1(1, N + 1) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { int min = i, max = 0; if (min > j) { min = j; } if (min > k) { min = k; } for (int l = 1; l <= min; l++) { if (i % l == 0 && j % l == 0 && k % l == 0) { max = l; } } sum += max; } } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; #define froop1(a, n) for (long long i = a; i < n; i++) #define froop2(a, n) for (int i = a; i > n; i--) int main() { long long N, sum = 0; cin >> N; froop1(1, N + 1) { for (int j = 1; j <= N; j++) { for (int k = 1; k <= N; k++) { sum += gcd(i, gcd(j, k)); } } } cout << sum << endl; }
replace
11
24
11
12
TLE
p02713
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define PI 3.141592653589 #define ll long long using namespace std; int gcd(int x, int y) { if (x % y == 0) return y; return gcd(y, x % y); } int main() { int k; cin >> k; int ans = 0; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= k; ++j) { for (int h = 1; h <= k; ++k) { ans += gcd(gcd(i, j), h); } } } cout << ans; return 0; }
#include <bits/stdc++.h> #define PI 3.141592653589 #define ll long long using namespace std; int gcd(int x, int y) { if (x % y == 0) return y; return gcd(y, x % y); } int main() { int k; cin >> k; int ans = 0; for (int i = 1; i <= k; ++i) { for (int j = 1; j <= k; ++j) { for (int h = 1; h <= k; ++h) { ans += gcd(gcd(i, j), h); } } } cout << ans; return 0; }
replace
19
20
19
20
TLE
p02713
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const int INF = 1e9; const int MOD = 1e9 + 7; int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { int K; int ans = 0; cin >> K; rep(a, K) { rep(b, K) { rep(c, K) { ans += gcd(gcd(a, b), c); } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 1; i < (int)(n + 1); i++) const int INF = 1e9; const int MOD = 1e9 + 7; int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int main() { int K; int ans = 0; cin >> K; rep(a, K) { rep(b, K) { rep(c, K) { ans += gcd(gcd(a, b), c); } } } cout << ans << endl; }
replace
3
4
3
4
-8