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

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

vector<pair<int, double>> G[100000];
double p;
int n;
int deep = 0;
double ans = 0;
double ans2;

vector<int> used(100000, 0);
vector<int> used1(100000, 0);

void dfs(int x) {

  deep++;
  for (int i = 0; i < G[x].size(); i++) {
    if (used[G[x][i].first] == 0) {
      used[G[x][i].first] = 1;
      ans += pow(p, deep) * G[x][i].second;
      dfs(G[x][i].first);
    }
  }
  deep--;
}

void dfs2(int x) {
  deep++;
  for (int i = 0; i < G[x].size(); i++) {
    if (used1[G[x][i].first] == 0) {
      used1[G[x][i].first] = 1;
      ans2 += pow(p, deep) * (G[x][i].second + ans);
      dfs2(G[x][i].first);
    }
  }
  deep--;
}

int main() {
  cin >> p >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    double c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  used[0] = 1;
  used1[0] = 1;
  dfs(0);
  ans2 = ans;
  deep = 0;
  dfs2(0);

  cout << fixed << setprecision(10) << ans2 << endl;
}


Error: -11

Fixed submission:

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

vector<pair<int, double>> G[100000];
double p;
int n;
int deep = 0;
double ans = 0;
double ans2;

vector<int> used(100000, 0);
vector<int> used1(100000, 0);

void dfs(int x) {

  deep++;
  for (int i = 0; i < G[x].size(); i++) {
    if (used[G[x][i].first] == 0) {
      ans += pow(p, deep) * G[x][i].second;
      dfs(G[x][i].first);
    }
  }
  deep--;
}

void dfs2(int x) {
  deep++;
  for (int i = 0; i < G[x].size(); i++) {
    if (used1[G[x][i].first] == 0) {
      ans2 += pow(p, deep) * (G[x][i].second + ans);
      dfs2(G[x][i].first);
    }
  }
  deep--;
}

int main() {
  cin >> p >> n;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    double c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back(make_pair(b, c));
    G[b].push_back(make_pair(a, c));
  }
  dfs(0);
  ans2 = ans;
  deep = 0;
  dfs2(0);

  cout << fixed << setprecision(10) << ans2 << endl;
}
Problem p01907 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

double p, T;
int N;

double dfs1(int node, double pp, int prev,
            vector<vector<pair<int, int>>> &Cost) {
  double e = 0;
  for (auto nn : Cost[node]) {
    if (nn.first == prev)
      continue;
    e += nn.second * pp;
    e += dfs1(nn.first, pp * p, node, Cost);
  }
  return e;
}

double dfs2(int node, double pp, int prev,
            vector<vector<pair<int, int>>> &Cost) {
  double e = 0;
  for (auto nn : Cost[node]) {
    if (nn.first == prev)
      continue;
    e += (nn.second + T) * pp;
    e += dfs2(nn.first, pp * p, node, Cost);
  }
  return e;
}

int main(void) {
  cin >> p >> N;

  vector<vector<pair<int, int>>> Cost(N);

  for (int i = 0; i < N - 1; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    Cost[x].push_back(pair<int, int>(y, c));
    Cost[y].push_back(pair<int, int>(x, c));
  }

  T = dfs1(0, p, -1, Cost);

  double res = dfs2(0, p, -1, Cost) + T;
  printf("%.10f\\n", res);

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

double p, T;
int N;
vector<vector<int>> Cost;

double dfs1(int node, int h) {
  double e = 0;
  for (int i = 0; i < N; i++) {
    if (Cost[node][i] == -1)
      continue;
    e += Cost[node][i] * pow(p, h + 1);
    e += dfs1(i, h + 1);
  }
  return e;
}

double dfs2(int node, int h) {
  double e = 0;
  for (int i = 0; i < N; i++) {
    if (Cost[node][i] == -1)
      continue;
    e += (Cost[node][i] + T) * pow(p, h + 1);
    e += dfs2(i, h + 1);
  }
  return e;
}

int main(void) {
  cin >> p >> N;

  Cost.assign(N, vector<int>(N, -1));

  for (int i = 0; i < N - 1; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    Cost[x][y] = c;
  }

  T = dfs1(0, 0);

  double res = dfs2(0, 0) + T;
  printf("%.10f\\n", res);

  return 0;
}
Problem p01907 (C++) — buggy submission, verdict: Runtime Error

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
inline double getDouble() {
  double s;
  scanf("%lf", &s);
  return s;
}

#include <queue>
#include <set>

using namespace std;

vector<pair<int, int>> g[100000];
double pp[100000];
double p;

double dfs(int pos, double prob = 1, int prev = -1) {
  ::pp[pos] = prob;

  double ans = 0;
  REP(i, g[pos].size()) {
    const int next = g[pos][i].first;
    const int c = g[pos][i].second;

    if (next != prev) {
      ans += p * (c + dfs(next, prob * p, pos));
    }
  }

  return ans;
}

int main() {
  ::p = getDouble();
  const int n = getInt();

  REP(i, n - 1) {
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    const int c = getInt();

    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }

  const double t = dfs(0);

  double ans = t;
  REP(i, n) { ans += pp[i] * t; }

  printf("%.10f\\n", ans);
}

Error: 0

Fixed submission:

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

#include <cstdio>
inline int getInt() {
  int s;
  scanf("%d", &s);
  return s;
}
inline double getDouble() {
  double s;
  scanf("%lf", &s);
  return s;
}

#include <queue>
#include <set>

using namespace std;

vector<pair<int, int>> g[10000];
double pp[100000];
double p;

double dfs(int pos, double prob = 1, int prev = -1) {
  ::pp[pos] = prob;

  double ans = 0;
  REP(i, g[pos].size()) {
    const int next = g[pos][i].first;
    const int c = g[pos][i].second;

    if (next != prev) {
      ans += p * (c + dfs(next, prob * p, pos));
    }
  }

  return ans;
}

int main() {
  ::p = getDouble();
  const int n = getInt();

  REP(i, n - 1) {
    const int a = getInt() - 1;
    const int b = getInt() - 1;
    const int c = getInt();

    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }

  const double t = dfs(0);

  double ans = t;
  REP(i, n) { ans += pp[i] * t; }

  printf("%.10f\\n", ans);
}
Problem p01907 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
#include <vector>

#define DEBUG
#define NMAX 100000

using namespace std;

typedef struct s {
  int y, c;
} S;

double p;
double AddC;
double sum2 = 0;
int N;

vector<S> v[NMAX + 1];
bool f[NMAX + 1];

double dfs(int n, double P, int C) {
  // cout<<n<<","<<P<<","<<C<<endl;
  double sum = 0;
  for (int i = 0; i < v[n].size(); i++) {
    if (f[v[n][i].y] == false) {
      f[v[n][i].y] = true;
      sum += dfs(v[n][i].y, P * p, v[n][i].c);
    }
  }
  // cout<<"ret:"<<sum<<endl;
  return (double)C + sum * p;
}

double dfs2(int n, double P, int C) {
  double sum = 0;
  for (int i = 0; i < v[n].size(); i++) {
    if (f[v[n][i].y] == false) {
      f[v[n][i].y] = true;
      sum += dfs2(v[n][i].y, P * p, v[n][i].c);
    }
  }
  return (double)C + sum * p + AddC;
}

int main() {
  int x, y, c;

  cin >> p;
  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> x >> y >> c;
    S SS;
    SS.y = y;
    SS.c = c;
    v[x].push_back(SS);
    SS.y = x;
    v[y].push_back(SS);
  }

  for (int i = 0; i <= N; i++)
    f[i] = false;
  f[1] = true;
  AddC = dfs(1, 1, 0);
  // cout<<AddC<<endl;
  for (int i = 0; i <= N; i++)
    f[i] = false;
  f[1] = true;
  printf("%.8f\\n", dfs2(1, 1, 0));
}


Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>
#include <vector>

#define DEBUG
#define NMAX 100000

using namespace std;

typedef struct s {
  int y, c;
} S;

double p;
double AddC;
double sum2 = 0;
int N;
vector<S> v[NMAX];

double dfs(int n, double P, int C) {
  // cout<<n<<","<<P<<","<<C<<endl;
  double sum = 0;
  for (int i = 0; i < v[n].size(); i++) {
    sum += dfs(v[n][i].y, P * p, v[n][i].c);
  }
  // cout<<"ret:"<<sum<<endl;
  return (double)C * P + sum;
}

double dfs2(int n, double P, int C) {
  double sum = 0;
  for (int i = 0; i < v[n].size(); i++) {
    sum += dfs2(v[n][i].y, P * p, v[n][i].c);
  }
  return (double)C * P + sum + AddC * P;
}

int main() {
  int x, y, c;

  cin >> p;
  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    cin >> x >> y >> c;
    S SS;
    SS.y = y;
    SS.c = c;
    v[x].push_back(SS);
  }

  AddC = dfs(1, 1, 0);
  // cout<<AddC<<endl;
  printf("%.8f\\n", dfs2(1, 1, 0));
}
Problem p01908 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

unordered_map<string, bool> m;
string str = "";

bool func(int pos, int num) {
  if (pos == num) {
    if (m.find(str) == m.end()) {
      cout << str << endl;
      return true;
    }
    return false;
  }
  for (int i = 0; i < 26; i++) {
    str[pos] = 'a' + i;
    if (func(pos + 1, num)) {
      return true;
    }
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    for (int i = 1; i <= 4; i++) {
      for (int j = 0; j < (int)S.size() - i + 1; j++) {
        m[S.substr(j, i)] = true;
      }
    }
  }
  for (int i = 1; i <= 4; i++) {
    str += " ";
    if (func(0, i)) {
      return 0;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

unordered_map<string, bool> m;
string str = "";

bool func(int pos, int num) {
  if (pos == num) {
    if (m.find(str) == m.end()) {
      cout << str << endl;
      return true;
    }
    return false;
  }
  for (int i = 0; i < 26; i++) {
    str[pos] = 'a' + i;
    if (func(pos + 1, num)) {
      return true;
    }
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    for (int i = 1; i <= 4; i++) {
      for (int j = 0; j < S.size() - i + 1; j++) {
        m[S.substr(j, i)] = true;
      }
    }
  }
  for (int i = 1; i <= 4; i++) {
    str += " ";
    if (func(0, i)) {
      return 0;
    }
  }
  return 0;
}
Problem p01908 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  int N;
  cin >> N;
  vector<string> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S.push_back(s);
  }
  set<string> st;
  for (int i = 0; i < N; i++) {
    string s = S[i];
    for (int j = 1; j <= 4; j++) {
      for (int k = 0; k + j <= s.size(); k++) {
        st.insert(s.substr(k, j));
      }
    }
  }
  vector<int> vec(5, -1);
  while (1) {
    bool carry = true;
    for (int i = 0; carry; i++) {
      carry = false;
      vec[i]++;
      if (vec[i] >= 26) {
        vec[i] = 0;
        carry = true;
      }
    }
    if (~vec[4])
      break;
    string ans = "";
    for (int i = 0; vec[i] != -1; i++)
      ans += 'a' + vec[i];
    reverse(ans.begin(), ans.end());
    if (st.count(ans))
      continue;
    else {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> S;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    S.push_back(s);
  }
  set<string> st;
  for (int i = 0; i < N; i++) {
    string s = S[i];
    for (int j = 1; j <= s.size(); j++) {
      for (int k = 0; k + j <= s.size(); k++) {
        st.insert(s.substr(k, j));
      }
    }
  }
  vector<int> vec(5, -1);
  while (1) {
    bool carry = true;
    for (int i = 0; carry; i++) {
      carry = false;
      vec[i]++;
      if (vec[i] >= 26) {
        vec[i] = 0;
        carry = true;
      }
    }
    if (~vec[4])
      break;
    string ans = "";
    for (int i = 0; vec[i] != -1; i++)
      ans += 'a' + vec[i];
    reverse(ans.begin(), ans.end());
    if (st.count(ans))
      continue;
    else {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}
Problem p01908 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const int MAX = 1000000;
bool a[MAX];

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  FOR(l, 1, 5) {
    REP(i, n) {
      if (s[i].length() < l)
        continue;
      REP(j, s[i].length() - l + 1) {
        ll p = 0;
        REP(k, l) { p = 27 * p + s[i][j + k] - 'a' + 1; }
        if (p >= MAX)
          break;
        a[p] = true;
      }
    }
  }

  FOR(i, 1, MAX - 1) {
    if (a[i])
      continue;
    int x = i;
    string ans;
    bool f = true;
    while (x) {
      if (x % 27 == 0)
        f = false;
      char c = (x % 27) - 1 + 'a';
      ans = c + ans;
      x /= 27;
    }
    if (f) {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const int MAX = 1000000;
bool a[MAX];

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  REP(i, n) cin >> s[i];
  FOR(l, 1, 5) {
    REP(i, n) {
      REP(j, s[i].length() - l + 1) {
        ll p = 0;
        REP(k, l) { p = 27 * p + s[i][j + k] - 'a' + 1; }
        if (p >= MAX)
          break;
        a[p] = true;
      }
    }
  }

  FOR(i, 1, MAX - 1) {
    if (a[i])
      continue;
    int x = i;
    string ans;
    bool f = true;
    while (x) {
      if (x % 27 == 0)
        f = false;
      char c = (x % 27) - 1 + 'a';
      ans = c + ans;
      x /= 27;
    }
    if (f) {
      cout << ans << endl;
      return 0;
    }
  }

  return 0;
}
Problem p01908 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
int N;
string S[111111];

int en(string s) {
  int ret = 0;
  rep(i, s.size()) ret = ret * 26 + s[i] - 'a';

  int t = 26;
  for (int i = 1; i < s.size(); i++) {
    ret += t;
    t *= 26;
  }
  return ret;
}

const int MAX = 26 * 26 * 26 * 26;
bool ex[MAX * 4];

string smin(string &a, string &b) {
  if (a.size() < b.size())
    return a;
  if (a.size() > b.size())
    return b;
  return min(a, b);
}

signed main() {
  cin >> N;
  rep(i, N) cin >> S[i];

  rep(i, N) {
    rep(j, S[i].size()) {
      for (int len = 1; len <= 4 && j + len <= S[i].size(); len++) {
        int tmp = en(S[i].substr(j, len));
        ex[tmp] = 1;
      }
    }
  }

  string ans = "zzzzzzz";
  for (char a = 'a'; a <= 'z'; a++) {
    string s = string(1, a);
    if (!ex[en(s)])
      ans = smin(ans, s);
    for (char b = 'a'; b <= 'z'; b++) {
      string t = s + string(1, b);
      if (!ex[en(t)])
        ans = smin(ans, t);
      for (char c = 'a'; c <= 'z'; c++) {
        string u = t + string(1, c);
        if (!ex[en(u)])
          ans = smin(ans, u);
        for (char d = 'a'; d <= 'z'; d++) {
          string v = u + string(1, d);
          if (!ex[en(v)])
            ans = smin(ans, v);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Error: -11

Fixed submission:

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
int N;
string S[111111];

int en(string s) {
  int ret = 0;
  rep(i, s.size()) ret = ret * 26 + s[i] - 'a';

  int t = 26;
  for (int i = 1; i < s.size(); i++) {
    ret += t;
    t *= 26;
  }
  return ret;
}

const int MAX = 26 * 26 * 26 * 26;
bool ex[MAX];

string smin(string &a, string &b) {
  if (a.size() < b.size())
    return a;
  if (a.size() > b.size())
    return b;
  return min(a, b);
}

signed main() {
  cin >> N;
  rep(i, N) cin >> S[i];

  rep(i, N) {
    rep(j, S[i].size()) {
      for (int len = 1; len <= 4 && j + len <= S[i].size(); len++) {
        int tmp = en(S[i].substr(j, len));
        ex[tmp] = 1;
      }
    }
  }

  string ans = "zzzzzzz";
  for (char a = 'a'; a <= 'z'; a++) {
    string s = string(1, a);
    if (!ex[en(s)])
      ans = smin(ans, s);
    for (char b = 'a'; b <= 'z'; b++) {
      string t = s + string(1, b);
      if (!ex[en(t)])
        ans = smin(ans, t);
      for (char c = 'a'; c <= 'z'; c++) {
        string u = t + string(1, c);
        if (!ex[en(u)])
          ans = smin(ans, u);
        for (char d = 'a'; d <= 'z'; d++) {
          string v = u + string(1, d);
          if (!ex[en(v)])
            ans = smin(ans, v);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p01908 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
set<string> words;

int main() {
  words.clear();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];

  rep(i, N) {
    int n = S[i].length();
    for (int len = 1; len <= min(4, n); ++len) {
      for (int j = 0; j < n; ++j) {
        string t = S[i].substr(j, len);
        words.insert(t);
      } // end for
    }   // end for
  }     // end rep

  for (int i = 0; i < 27; ++i) {
    for (int j = 0; j < 27; ++j) {
      for (int k = 0; k < 27; ++k) {
        for (int m = 0; m < 26; ++m) {
          string s = "";
          if (i != 0)
            s += (char)('a' + i - 1);
          if (j != 0)
            s += (char)('a' + j - 1);
          if (k != 0)
            s += (char)('a' + k - 1);
          s += (char)('a' + m);
          if (!words.count(s)) {
            cout << s << endl;
            return 0;
          } // end if
        }   // end for
      }     // end for
    }       // end for
  }         // end for

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
set<string> words;

int main() {
  words.clear();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S[i];

  rep(i, N) {
    int n = S[i].length();
    for (int len = 1; len <= n; ++len) {
      for (int j = 0; j < n; ++j) {
        string t = S[i].substr(j, len);
        if (t.length() <= 4) {
          words.insert(t);
        } // end if
      }   // end for
    }     // end for
  }       // end rep

  for (int i = 0; i < 27; ++i) {
    for (int j = 0; j < 27; ++j) {
      for (int k = 0; k < 27; ++k) {
        for (int m = 0; m < 26; ++m) {
          string s = "";
          if (i != 0)
            s += (char)('a' + i - 1);
          if (j != 0)
            s += (char)('a' + j - 1);
          if (k != 0)
            s += (char)('a' + k - 1);
          s += (char)('a' + m);
          if (!words.count(s)) {
            cout << s << endl;
            return 0;
          } // end if
        }   // end for
      }     // end for
    }       // end for
  }         // end for

  return 0;
}
Problem p01908 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 2147483600

inline int code(string s) {
  int ret = 0;
  for (auto c : s)
    ret = ret * 100 + c;
  return ret;
}

set<int> s;

bool dfs(string str, int d, int p) {
  if (d == 0) {
    cout << str << endl;
    return true;
  }
  str.pb('a');
  int l = str.size();
  rep(i, 26) {
    if (l >= p && s.count(code(str.substr(l - p)))) {
    } else if (dfs(str, d - 1, p))
      return true;
    str[l - 1]++;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  rep(i, n) cin >> vec[i];

  repl(i, 1, 6) {
    s.clear();
    for (auto &str : vec) {
      int l = str.size();
      rep(j, l - i + 1) s.insert(code(str.substr(j, i)));
    }
    if (dfs("", i, i))
      break;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
  o << "(" << p.fi << "," << p.se << ")";
  return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "[";
  for (T t : v) {
    o << t << ",";
  }
  o << "]";
  return o;
}

#define INF 2147483600

inline int code(char c, char d) { return c * 100 + d; }

set<int> s;

bool dfs(string str, int d) {
  if (d == 0) {
    int l = str.size();
    rep(i, l - 1) if (s.count(code(str[i], str[i + 1]))) return false;
    cout << str << endl;
    return true;
  }
  rep(i, 26) {
    str.pb(i + 'a');
    if (dfs(str, d - 1))
      return true;
    str.pop_back();
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  vector<string> vec(n);
  rep(i, n) cin >> vec[i];

  set<char> sc;
  rep(i, n) for (auto c : vec[i]) sc.insert(c);
  rep(i, 26) if (sc.count(i + 'a') == 0) {
    cout << string(1, i + 'a') << endl;
    return 0;
  }

  rep(i, n) {
    int l = vec[i].size();
    rep(j, l - 1) s.insert(code(vec[i][j], vec[i][j + 1]));
  }
  repl(i, 2, 10) {
    if (dfs("", i))
      break;
  }

  return 0;
}