alexjercan/bugnet huggingface dataset:
Problem p02710 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

const int L = 2e5 + 9;
LL c[L];
vector<int> es[L];
LL ps[L];
LL w[L];
LL cnt[L];
LL ret[L];
LL N;
LL dfs(int r, int p) {
  int pcnt = cnt[c[r]];
  int pps = ps[c[r]];
  ps[c[r]] = r;
  LL s = 1;
  ret[c[r]] += s;
  LL sum = 1;
  for (auto i : es[r]) {
    if (i == p) {
      continue;
    }
    w[r] = 0;
    auto v = dfs(i, r);
    auto t = w[r] + v;
    ret[c[r]] += t * s;
    s += t;
    sum += v;
  }
  {
    auto t = N - sum - pcnt;
    ret[c[r]] += t * s;
  }
  cnt[c[r]] += s;
  w[pps] -= sum;
  ps[c[r]] = pps;
  return sum;
}

int main() {
  scanf("%lld", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &c[i]);
  }
  for (int i = 0; i < N - 1; i++) {
    LL a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    es[a].push_back(b);
    es[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 1; i <= N; i++) {
    cout << ret[i] << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

const int L = 2e5;
LL c[L];
vector<int> es[L];
LL ps[L];
LL w[L];
LL cnt[L];
LL ret[L];
LL N;
LL dfs(int r, int p) {
  int pcnt = cnt[c[r]];
  int pps = ps[c[r]];
  ps[c[r]] = r;
  LL s = 1;
  ret[c[r]] += s;
  LL sum = 1;
  for (auto i : es[r]) {
    if (i == p) {
      continue;
    }
    w[r] = 0;
    auto v = dfs(i, r);
    auto t = w[r] + v;
    ret[c[r]] += t * s;
    s += t;
    sum += v;
  }
  {
    auto t = N - sum - pcnt;
    ret[c[r]] += t * s;
  }
  cnt[c[r]] += s;
  w[pps] -= sum;
  ps[c[r]] = pps;
  return sum;
}

int main() {
  scanf("%lld", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &c[i]);
  }
  for (int i = 0; i < N - 1; i++) {
    LL a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    es[a].push_back(b);
    es[b].push_back(a);
  }
  dfs(1, 0);
  for (int i = 1; i <= N; i++) {
    cout << ret[i] << endl;
  }
  return 0;
}
Problem p02710 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
vector<int> G[N];
int n, col[N], cnt[N], all;
ll ans[N], sz[N];
ll dfs(int u, int fa) {
  ll tmp = cnt[col[u]];
  sz[u] = 1;
  for (int v : G[u]) {
    if (v == fa)
      continue;
    ll l = all - cnt[col[u]];
    sz[u] += dfs(v, u);
    ll r = all - cnt[col[u]];
    ll len = r - l;
    ans[col[u]] -= (len * (len - 1) / 2);
  }
  cnt[col[u]] = tmp + sz[u];
  all++;
  return sz[u];
  ;
}
int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", &col[i]);
  rep(i, 2, n) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }

  rep(i, 1, n) ans[i] = 1ll * n * (n - 1) / 2;
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) {
    // printf("i:%d cnt:%d ans:%lld\\n",i,cnt[i],ans[i]);
    ll len = n - cnt[i];
    ans[i] -= (len * (len - 1) / 2);
  }
  for (int i = 1; i <= n; ++i)
    ans[col[i]]++; // 每个单独的点是一条路径
  for (int i = 1; i <= n; ++i)
    printf("%lld\\n", ans[i]);
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
vector<int> G[N];
int n, col[N], cnt[N], all;
ll ans[N], sz[N];
ll dfs(int u, int fa) {
  ll tmp = cnt[col[u]];
  sz[u] = 1;
  for (int v : G[u]) {
    if (v == fa)
      continue;
    ll l = all - cnt[col[u]];
    sz[u] += dfs(v, u);
    ll r = all - cnt[col[u]];
    ll len = r - l;
    ans[col[u]] -= (len * (len - 1) / 2);
  }
  cnt[col[u]] = tmp + sz[u];
  all++;
  return sz[u];
  ;
}
int main() {
  scanf("%d", &n);
  rep(i, 1, n) scanf("%d", &col[i]);
  rep(i, 2, n) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }

  rep(i, 1, n) ans[i] = 1ll * n * (n - 1) / 2;
  dfs(1, -1);
  for (int i = 1; i <= n; ++i) {
    // printf("i:%d cnt:%d ans:%lld\\n",i,cnt[i],ans[i]);
    ll len = n - cnt[i];
    ans[i] -= (len * (len - 1) / 2);
  }
  for (int i = 1; i <= n; ++i)
    ans[col[i]]++;
  for (int i = 1; i <= n; ++i)
    printf("%lld\\n", ans[i]);
}
Problem p02710 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N = 2e5 + 9;
int n, c[N], ans[N], sz[N];
int cnt[N];
vector<int> g[N];
void dfs(int v, int p) {
  int mx = 0, hold = cnt[c[v]];
  cnt[c[v]] = 0;
  for (auto u : g[v]) {
    if (u == p)
      continue;
    int prev = cnt[c[v]];
    dfs(u, v);
    sz[v] += sz[u];
    int del = cnt[c[v]] - prev;
    int x = sz[u] - del;
    ans[c[v]] += x * (x - 1) / 2 + x;
  }
  sz[v]++;
  cnt[c[v]] = sz[v] + hold;
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    int x = n - cnt[i];
    ans[i] += x * (x - 1) / 2 + x;
  }
  int k = n * (n - 1) / 2 + n;
  for (int i = 1; i <= n; i++)
    cout << k - ans[i] << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N = 2e5 + 9;
int n, c[N], ans[N], sz[N];
map<int, int> mp[N];
vector<int> g[N];
void dfs(int v, int p) {
  int hv = -1, mx = 0;
  for (auto u : g[v]) {
    if (u == p)
      continue;
    dfs(u, v);
    sz[v] += sz[u];
    int x = sz[u] - mp[u][c[v]];
    ans[c[v]] += x * (x - 1) / 2 + x;
    // if(mp[u].size()>mx)mx=mp[u].size(),hv=u;
  }
  // swap(mp[hv],mp[v]);
  for (auto u : g[v]) {
    if (u == p or u == hv)
      continue;
    for (auto i : mp[u])
      mp[v][i.f] += i.s;
  }
  sz[v]++;
  mp[v][c[v]] = sz[v];
}
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> c[i];
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; i++) {
    int x = n - mp[1][i];
    ans[i] += x * (x - 1) / 2 + x;
  }
  int k = n * (n - 1) / 2 + n;
  for (int i = 1; i <= n; i++)
    cout << k - ans[i] << '\\n';
}
Problem p02710 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int)2e5 + 7;
int n, col[N], sub[N], pr[N];
vector<int> g[N];
ll su[N], sol[N];

void build(int a) {
  sub[a] = 1;
  vector<int> kids;
  for (auto &b : g[a]) {
    if (sub[b] == 0) {
      pr[b] = a;
      kids.push_back(b);
      build(b);
      sub[a] += sub[b];
    }
  }
  g[a] = kids;
}

ll f(ll len) { return len * (len + 1) / 2; }

void dfs(int a) {
  int ini1 = su[col[a]];
  int ini2 = su[col[pr[a]]];
  for (auto &b : g[a]) {
    dfs(b);
  }
  su[col[a]] = ini1 + sub[a];
  int tot = su[col[pr[a]]] - ini2;
  tot = sub[a] - tot;
  sol[col[pr[a]]] += f(tot);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  build(1);
  dfs(1);
  for (int i = 1; i <= n; i++) {
    sol[i] += f(sub[1] - su[i]);
    sol[i] = f(n) - sol[i];
    cout << sol[i] << "\\n";
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int)2e5 + 7;
int n, col[N], sub[N];
vector<int> g[N], who[N], ord;
bool block[N];

void build(int a) {
  ord.push_back(a);
  sub[a] = 1;
  vector<int> kids;
  for (auto &b : g[a]) {
    if (sub[b] == 0) {
      kids.push_back(b);
      build(b);
      sub[a] += sub[b];
    }
  }
  g[a] = kids;
}

ll f(ll len) { return len * (len + 1) / 2; }

int cr;

void dfs(int a) {
  cr++;
  block[a] = 1;
  for (auto &b : g[a]) {
    if (block[b] == 0) {
      dfs(b);
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> col[i];
    who[col[i]].push_back(i);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  build(1);
  for (int cx = 1; cx <= n; cx++) {
    for (int i = 1; i <= n; i++) {
      block[i] = 0;
    }
    for (auto &i : who[cx]) {
      block[i] = 1;
    }
    ll sol = 0;
    for (auto &i : ord) {
      if (block[i] == 0) {
        cr = 0;
        dfs(i);
        sol += f(cr);
      }
    }
    cout << f(n) - sol << "\\n";
  }
  return 0;
}
Problem p02710 (C++) — buggy submission, verdict: 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[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]);
}

Error: 0

Fixed submission:

#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]);
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: 0

Fixed submission:

#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;
}
Problem p02711 (C++) — buggy submission, verdict: 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;
    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;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define f(i, l, n) for (int i = l; i < n; i++)
#define E "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1e18
#define float long double

const int N = 1e5 + 3;
int sol() {
  int n;
  cin >> n;
  while (n != 0) {
    if (n % 10 == 7) {
      cout << "Yes\\n", 0;
      return 0;
    }
    n /= 10;
  }
  cout << "No\\n";
  return 0;
}

int32_t main() { int t = sol(); }

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ll long long
#define f(i, l, n) for (int i = l; i < n; i++)
#define E "\\n"
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define MAX 1e18
#define float long double

const int N = 1e5 + 3;
int sol() {
  int n;
  cin >> n;
  while (n != 0) {
    if (n % 10 == 7)
      return cout << "Yes\\n", 0;
    n /= 10;
  }
  cout << "No\\n";
}

int32_t main() { sol(); }
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
// #include<bits/stdc++.h>
using namespace std;

void check(int N) {
  while (N) {
    int a = N % 10;
    if (a == 7) {
      cout << "Yes";
      return;
    }
    N = N / 10;
  }
  cout << "No";
}

int main() {
  int N;
  cin >> N;
  check(N);
}


Error: 1

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
using namespace std;

bool check(int N) {
  while (N) {
    int a = N % 10;
    if (a == 7)
      return true;
    N = N / 10;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  return check(N);
}
Problem p02711 (C++) — buggy submission, verdict: 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;
    }
    a /= 10;
  }
  cout << "No\\n";
}

Error: TLE

Fixed submission:

#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";
}
Problem p02711 (C++) — buggy submission, verdict: 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;
    }
    n /= 10;
  }
  if (f)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Error: TLE

Fixed submission:

#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;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main() {
  int t;
  cin >> t;
  int flag = 0;
  while (t > 0) {
    int dig = t % 10;
    if (dig == 7) {
      cout << "Yes" << endl;
      flag = 1;
      break;
    }
    t = t / 10;
  }
  if (flag == 1)
    return 0;
  cout << "No" << endl;
  return 0;
}

Error: 1

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

int main() {
  int t;
  cin >> t;
  while (t > 0) {
    int dig = t % 10;
    if (dig == 7) {
      cout << "Yes" << endl;
      return 1;
    }
    t = t / 10;
  }
  cout << "No" << endl;
  return 0;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#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;
}

Error: -6
terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string: construction from null is not valid


Fixed submission:

#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;
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
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;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string a;
  cin >> a;

  for (int i = 0; i < 1000; ++i) {
    if (a.at(i) == 7) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}
Problem p02711 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    if (n % 10 == 7) {
      cout << "Yes";
      break;
    }
    n = n / 10;
  }
  if (n == 0) {
    cout << "No";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  while (n > 0) {
    if (n % 10 == 7) {
      cout << "Yes";
      break;
      n = n / 10;
    }
  }
  if (n == 0) {
    cout << "No";
  }
}
Problem p02711 (C++) — buggy submission, verdict: 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;
    N /= 10;
    if (tmp == 7) {
      cout << "Yes" << endl;
      flg = false;
      break;
    }
  }
  if (flg == true) {
    cout << "No" << endl;
  }
}


Error: TLE

Fixed submission:

#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;
  }
}
Problem p02711 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  for (int i = 0; i < 3; i++) {
    // cout<<s.at(i)<<endl;
    if (s[i] == '7') {
      cout << "Yes" << endl;
      goto OUT;
    }
  }
  cout << "No" << endl;
OUT:;
}

Error: -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)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == '7') {
      cout << "Yes" << endl;
      goto OUT;
    }
  }
  cout << "No" << endl;
OUT:;
}