prithivMLmods/Coder-Stat huggingface dataset:
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }

int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  rep(i, n) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  for (int i = 999; i >= 0; i--) {
    str tmp = to_string(i);
    if ((int)tmp.size() != n)
      continue;
    bool is_ok = true;
    rep(j, m) if (tmp[sc[j].first] != sc[j].second) is_ok = false;
    if (is_ok)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T> T lcm(T a, T b) { return a / __gcd(a, b) * b; }

int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, char>> sc(m);
  rep(i, m) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    sc[i] = make_pair(s, c);
  }
  for (int i = 999; i >= 0; i--) {
    str tmp = to_string(i);
    if ((int)tmp.size() != n)
      continue;
    bool is_ok = true;
    rep(j, m) if (tmp[sc[j].first] != sc[j].second) is_ok = false;
    if (is_ok)
      ans = i;
  }
  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

using namespace std;
typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++)
    cin >> sc[i].first >> sc[i].second;

  int init = 0;
  int endon = 10;
  if (N == 2) {
    init = 10;
    endon = 100;
  }
  if (N == 3) {
    init = 100;
    endon = 1000;
  }

  ll ans = 10000;

  for (int i = init; i < endon; i++) {
    for (int j = 0; j < M; j++) {
      ll waru = 1;
      if (sc[j].first == 1)
        waru = 1;
      if (sc[j].first == 2)
        waru = 10;
      if (sc[j].first == 3)
        waru = 100;
      if (i / (init / waru) % 10 != sc[j].second) {
        break;
      }
      if (j == M - 1) {
        if (i < ans)
          ans = i;
      }
    }
  }

  if (ans != 10000)
    cout << ans << endl;
  else if (M == 0)
    cout << init << endl;
  else
    cout << -1 << endl;

  return 0;
}

// cout << setprecision(13);
// next_permutation();
//__gcd();
// reverse();
// set ,tuple ,pair;
// bitset
// vector.find
// vector.count


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

using namespace std;
typedef long long ll;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int N, M;
  cin >> N >> M;

  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++)
    cin >> sc[i].first >> sc[i].second;

  int init = 0;
  int endon = 10;
  if (N == 2) {
    init = 10;
    endon = 100;
  }
  if (N == 3) {
    init = 100;
    endon = 1000;
  }

  ll ans = 10000;

  for (int i = init; i < endon; i++) {
    for (int j = 0; j < M; j++) {
      ll waru = 1;
      if (sc[j].first == 1)
        waru = 1;
      if (sc[j].first == 2)
        waru = 10;
      if (sc[j].first == 3)
        waru = 100;
      ll waruwaru = init / waru;
      if (waruwaru == 0)
        waruwaru = 1;
      if ((i / waruwaru) % 10 != sc[j].second) {
        break;
      }
      if (j == M - 1) {
        if (i < ans)
          ans = i;
      }
    }
  }

  if (ans != 10000)
    cout << ans << endl;
  else if (M == 0)
    cout << init << endl;
  else
    cout << -1 << endl;

  return 0;
}

// cout << setprecision(13);
// next_permutation();
//__gcd();
// reverse();
// set ,tuple ,pair;
// bitset
// vector.find
// vector.count
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i, m) cin >> p[i].first >> p[i].second;
  rep(x, 1000) {
    int keta = 1;
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx) {
      keta++;
      d.push_back(nx % 10);
      nx / 10;
    }
    if (keta != n)
      continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    rep(i, m) {
      if (d[p[i].first - 1] != p[i].second)
        ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i, m) cin >> p[i].first >> p[i].second;
  rep(x, 1000) {
    int keta = 1;
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx) {
      keta++;
      d.push_back(nx % 10);
      nx /= 10;
    }
    if (keta != n)
      continue;
    bool ok = true;
    reverse(d.begin(), d.end());
    rep(i, m) {
      if (d[p[i].first - 1] != p[i].second)
        ok = false;
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }

  // sが同じでcが違うようなものが存在すれば-1
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      // iとjを比べる
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  if (n == 1) {
    cout << c[0] << endl;
    return 0;
  }

  // 1桁目が0なら-1
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> ans(n, 0);
  ans[0] = 1;
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }

  for (int x : ans)
    cout << x;

  cout << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }

  // sが同じでcが違うようなものが存在すれば-1
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      // iとjを比べる
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }

  if (n == 1) {
    cout << (m ? c[0] : 0) << endl;
    return 0;
  }

  // 1桁目が0なら-1
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> ans(n, 0);
  ans[0] = 1;
  for (int i = 0; i < m; i++) {
    ans[s[i] - 1] = c[i];
  }

  for (int x : ans)
    cout << x;

  cout << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, M, s, c, Ans = 0;
  cin >> N >> M;
  vector<int> vec(3);
  vec.at(0) = -1;
  vec.at(1) = -1;
  vec.at(2) = -1;

  rep(i, M) {
    cin >> s >> c;
    if (vec.at(s - 1) == -1 || vec.at(s - 1) == c) {
      vec.at(s - 1) = c;
    } else {
      Ans = -1;
      break;
    }
  }
  if (Ans == -1) {
    cout << -1 << endl;
  } else if (N == 1) {
    if (vec.at(0) == -1) {
      vec.at(0) = 0;
    }
    cout << vec.at(s - 1) << endl;
  } else if (vec.at(0) == 0) {
    cout << -1 << endl;
  } else {
    if (vec.at(0) == -1) {
      vec.at(0) = 1;
    }
    if (vec.at(1) == -1) {
      vec.at(1) = 0;
    }

    if (N == 2) {
      cout << vec.at(0) * 10 + vec.at(1) << endl;
    } else {
      if (vec.at(2) == -1) {
        vec.at(2) = 0;
      }
      cout << vec.at(0) * 100 + vec.at(1) * 10 + vec.at(2) << endl;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N, M, s, c, Ans = 0;
  cin >> N >> M;
  vector<int> vec(3);
  vec.at(0) = -1;
  vec.at(1) = -1;
  vec.at(2) = -1;

  rep(i, M) {
    cin >> s >> c;
    if (vec.at(s - 1) == -1 || vec.at(s - 1) == c) {
      vec.at(s - 1) = c;
    } else {
      Ans = -1;
      break;
    }
  }
  if (Ans == -1) {
    cout << -1 << endl;
  } else if (N == 1) {
    if (vec.at(0) == -1) {
      vec.at(0) = 0;
    }
    cout << vec.at(0) << endl;
  } else if (vec.at(0) == 0) {
    cout << -1 << endl;
  } else {
    if (vec.at(0) == -1) {
      vec.at(0) = 1;
    }
    if (vec.at(1) == -1) {
      vec.at(1) = 0;
    }

    if (N == 2) {
      cout << vec.at(0) * 10 + vec.at(1) << endl;
    } else {
      if (vec.at(2) == -1) {
        vec.at(2) = 0;
      }
      cout << vec.at(0) * 100 + vec.at(1) * 10 + vec.at(2) << endl;
    }
  }
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++)
    cin >> s[i] >> c[i];
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (n >= 2 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (n == 1) {

    cout << c[0] << endl;
  }
  if (n == 2) {
    int a = 1;
    int b = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1)
        a = c[i];
      if (s[i] == 2)
        b = c[i];
    }
    cout << 10 * a + b << endl;
  }
  if (n == 3) {
    int p = 1;
    int q = 0;
    int r = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1)
        p = c[i];
      if (s[i] == 2)
        q = c[i];
      if (s[i] == 3)
        r = c[i];
    }
    cout << 100 * p + 10 * q + r << endl;
  }
}

Fixed submission:
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < m; i++)
    cin >> s[i] >> c[i];
  if (m == 0) {
    if (n == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (n == 2) {
      cout << 10 << endl;
      return 0;
    }
    if (n == 3) {
      cout << 100 << endl;
      return 0;
    }
  }
  for (int i = 1; i < m; i++) {
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < m; i++) {
    if (n >= 2 && s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (n == 1) {

    cout << c[0] << endl;
  }
  if (n == 2) {
    int a = 1;
    int b = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1)
        a = c[i];
      if (s[i] == 2)
        b = c[i];
    }
    cout << 10 * a + b << endl;
  }
  if (n == 3) {
    int p = 1;
    int q = 0;
    int r = 0;
    for (int i = 0; i < m; i++) {
      if (s[i] == 1)
        p = c[i];
      if (s[i] == 2)
        q = c[i];
      if (s[i] == 3)
        r = c[i];
    }
    cout << 100 * p + 10 * q + r << endl;
  }
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int power(int n, int t) {
  int s = 1;
  repi(i, t, 0) { s *= n; }
  return s;
}

int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, int>> b(m);
  repi(i, m, 0) {
    int s, c;
    cin >> s >> c;
    b[i] = make_pair(s, c);
  }

  repi(i, power(10, n), power(10, n - 1) - 1) {
    bool state = true;
    repi(j, m, 0) {
      string num = to_string(i);
      if (num.at(b.at(j).first - 1) - '0' != b.at(j).second) {
        state = false;
        break;
      }
    }
    if (state) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <iomanip>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
const long INF = 1e9;
const long MOD = 1e9 + 7;
#define repi(i, n, init) for (int i = init; i < int(n); i++)

int power(int n, int t) {
  int s = 1;
  repi(i, t, 0) { s *= n; }
  return s;
}

int main() {
  int n, m, ans = -1;
  cin >> n >> m;
  vector<pair<int, int>> b(m);
  repi(i, m, 0) {
    int s, c;
    cin >> s >> c;
    b[i] = make_pair(s, c);
  }

  repi(i, power(10, n), power(10, n - 1) - (n == 1 ? 1 : 0)) {
    bool state = true;
    repi(j, m, 0) {
      string num = to_string(i);
      if (num.at(b.at(j).first - 1) - '0' != b.at(j).second) {
        state = false;
        break;
      }
    }
    if (state) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ke(n, -1), c(m), s(m);
  int flag = 1;

  if (n == 1) {
    for (int i = 0; i < m; i++) {
      cin >> s[i] >> c[i];
    }
    for (int i = 0; i < m - 1; i++) {
      if (c[i] == c[i + 1]) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c[0] << "\n";
    return 0;
  }

  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[0] == 1 && c[0] == 0) {
      flag = 0;
    }

    if (ke[s[i] - 1] == -1 || ke[s[i] - 1] == c[i]) {
      ke[s[i] - 1] = c[i];
    } else {
      flag = 0;
    }
  }
  if (ke[0] == -1) {
    ke[0] = 1;
  }

  if (flag == 1) {
    for (int i = 0; i < n; i++) {
      if (ke[i] == -1) {
        cout << 0;
      } else {
        cout << ke[i];
      }
    }
  } else {
    cout << -1;
  }
  cout << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ke(n, -1), c(m), s(m);
  int flag = 1;

  if (n == 1 && m == 0) {
    cout << 0 << endl;
    return 0;
  }

  if (n == 1) {
    for (int i = 0; i < m; i++) {
      cin >> s[i] >> c[i];
    }
    for (int i = 0; i < m - 1; i++) {
      if (c[i] == c[i + 1]) {
        continue;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c[0] << "\n";
    return 0;
  }

  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[0] == 1 && c[0] == 0) {
      flag = 0;
    }

    if (ke[s[i] - 1] == -1 || ke[s[i] - 1] == c[i]) {
      ke[s[i] - 1] = c[i];
    } else {
      flag = 0;
    }
  }
  if (ke[0] == -1) {
    ke[0] = 1;
  }

  if (flag == 1) {
    for (int i = 0; i < n; i++) {
      if (ke[i] == -1) {
        cout << 0;
      } else {
        cout << ke[i];
      }
    }
  } else {
    cout << -1;
  }
  cout << endl;

  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> s(m);
  vector<int> c(m);
  rep(i, m) { cin >> s.at(i) >> c.at(i); }

  vector<int> t(m);
  rep(i, n) t[i] = -1;

  rep(j, m) {
    if (t[s[j] - 1] == -1)
      t[s[j] - 1] = c[j];
    else if (t[s[j] - 1] != c[j]) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (n == 1)
    t[0] = max(t[0], 0);
  else if (t[0] != 0)
    t[0] = max(t[0], 1);
  else {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (t[i] == -1)
      t[i] = 0;
  }

  int ans = 0;
  int v;

  for (int i = 0; i < n; i++) {
    v = (int)pow(10, n - i - 1);
    ans += t[i] * v;
    //    cout << t[i] << " " << v << endl;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> s(m);
  vector<int> c(m);
  rep(i, m) { cin >> s.at(i) >> c.at(i); }

  vector<int> t(n);
  rep(i, n) t[i] = -1;

  rep(j, m) {
    if (t[s[j] - 1] == -1)
      t[s[j] - 1] = c[j];
    else if (t[s[j] - 1] != c[j]) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (n == 1)
    t[0] = max(t[0], 0);
  else if (t[0] != 0)
    t[0] = max(t[0], 1);
  else {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < n; i++) {
    if (t[i] == -1)
      t[i] = 0;
  }

  int ans = 0;
  int v;

  for (int i = 0; i < n; i++) {
    v = (int)pow(10, n - i - 1);
    ans += t[i] * v;
    //    cout << t[i] << " " << v << endl;
  }
  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using vvii = vector<vector<int>>;
using vvll = vector<vector<ll>>;

const ll inf = 1LL << 60;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  vector<int> exist(M, -1);
  bool flag = true;
  REP(i, M) {
    int s, c;
    cin >> s >> c;
    if (exist[s - 1] == -1) {
      exist[s - 1] = c;
    } else {
      if (exist[s - 1] == c)
        continue;
      else {
        flag = false;
        break;
      }
    }
  }
  if (!flag || (N > 1 && exist[0] == 0)) {
    cout << -1 << endl;
    return 0;
  }

  REP(i, N) {
    if (exist[i] == -1) {
      if (i == 0 && N > 1)
        exist[i] = 1;
      else
        exist[i] = 0;
    }
  }
  int ans = 0;
  REP(i, N) { ans += exist[i] * pow(10, N - i - 1); }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;
using vvii = vector<vector<int>>;
using vvll = vector<vector<ll>>;

const ll inf = 1LL << 60;

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  // cout << fixed << setprecision(15);
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  vector<int> exist(N, -1);
  bool flag = true;
  REP(i, M) {
    int s, c;
    cin >> s >> c;
    if (exist[s - 1] == -1) {
      exist[s - 1] = c;
    } else {
      if (exist[s - 1] == c)
        continue;
      else {
        flag = false;
        break;
      }
    }
  }
  if (!flag || (N > 1 && exist[0] == 0)) {
    cout << -1 << endl;
    return 0;
  }

  REP(i, N) {
    if (exist[i] == -1) {
      if (i == 0 && N > 1)
        exist[i] = 1;
      else
        exist[i] = 0;
    }
  }
  int ans = 0;
  REP(i, N) { ans += exist[i] * pow(10, N - i - 1); }
  cout << ans << endl;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int times10(int n) {
  int output = 1;
  for (int i = 0; i < n; i++) {
    output *= 10;
  }
  return output;
}

int main() {
  // enter
  int N, M;
  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }

  vector<int> output(N, -1);

  // program
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else if (N == 2) {
      cout << 10 << endl;
      return 0;
    } else {
      cout << 10 << endl;
      return 100;
    }
  }

  for (int i = 0; i < M; i++) {
    if (N > 1 && s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }

    if (output[s[i]] == -1) {
      output[s[i]] = c[i];
    } else if (output[s[i]] == c[i]) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  int num;
  if (output[0] == -1) {
    if (N == 0) {
      num = 0;
    } else {
      num = times10(N - 1);
    }
  } else {
    num = times10(N - 1) * output[0];
  }

  for (int i = 1; i < N; i++) {
    if (output[i] != -1) {
      num += times10(N - 1 - i) * output[i];
    }
  }

  cout << num << endl;
  return 0;
}


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

int times10(int n) {
  int output = 1;
  for (int i = 0; i < n; i++) {
    output *= 10;
  }
  return output;
}

int main() {
  // enter
  int N, M;
  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }

  vector<int> output(N, -1);

  // program
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else if (N == 2) {
      cout << 10 << endl;
      return 0;
    } else {
      cout << 100 << endl;
      return 0;
    }
  }

  for (int i = 0; i < M; i++) {
    if (N > 1 && s[i] == 0 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }

    if (output[s[i]] == -1) {
      output[s[i]] = c[i];
    } else if (output[s[i]] == c[i]) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }

  int num;
  if (output[0] == -1) {
    if (N == 0) {
      num = 0;
    } else {
      num = times10(N - 1);
    }
  } else {
    num = times10(N - 1) * output[0];
  }

  for (int i = 1; i < N; i++) {
    if (output[i] != -1) {
      num += times10(N - 1 - i) * output[i];
    }
  }

  cout << num << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
int a[5];
void solve() {
  int n, m;
  cin >> n >> m;
  memset(a, -1, sizeof a);
  int sum = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (a[s] == -1 || a[s] == c) {
      sum += c;
      a[s] = c;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (n > 1 && a[1] == 0) {
    cout << -1 << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1 && a[i] == -1 && n > 1) {
      cout << 1;
      continue;
    }
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w+", stdout);
#endif
  solve();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define N 200100
int a[5];
void solve() {
  int n, m;
  cin >> n >> m;
  memset(a, -1, sizeof a);
  int sum = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (a[s] == -1 || a[s] == c) {
      sum += c;
      a[s] = c;
    } else {
      cout << -1 << endl;
      return;
    }
  }
  if (n > 1 && a[1] == 0) {
    cout << -1 << endl;
    return;
  }
  for (int i = 1; i <= n; i++) {
    if (i == 1 && a[i] == -1 && n > 1) {
      cout << 1;
      continue;
    }
    if (a[i] == -1)
      cout << 0;
    else
      cout << a[i];
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
}
Problem p02761 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    _s, _c = map(int, input().split())
    s.append(_s)
    c.append(_c)

for i in range(1000):
    (*t,) = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break

    if ok:
        print(i)
        quit()

print(-1)


Fixed submission:
n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    _s, _c = map(int, input().split())
    s.append(_s - 1)
    c.append(_c)

for i in range(1000):
    (*t,) = map(int, list(str(i)))

    if len(t) != n:
        continue

    ok = True
    for j in range(m):
        if t[s[j]] != c[j]:
            ok = False
            break

    if ok:
        print(i)
        quit()

print(-1)
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N, M, x = 100, y = 0, z = 0, ans;

  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);
  vector<int> d(3, 10);

  rep(i, M) cin >> s[i] >> c[i];

  if (N == 1) {
    ans = c[0];
  } else if (N == 2) {
    rep(i, M) {
      if (s[i] == 1) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    if (y == 0)
      y = 10;
    ans = y + z;
  }

  else if (N == 3) {
    rep(i, M) {
      if (s[i] == 1) {
        x = 100 * c[i];
      } else if (s[i] == 2) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    ans = x + y + z;
  }

  rep(i, M) {
    if (d[s[i] - 1] == 10) {
      d[s[i] - 1] = c[i];
    } else {
      if (d[s[i] - 1] != c[i])
        ans = -1;
      break;
    }
  }

  rep(i, M) {
    if (N == 2) {
      if (s[i] == 1 && c[i] == 0)
        ans = -1;
    } else if (N == 3) {
      if (s[i] == 1 && c[i] == 0)
        ans = -1;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int N, M, x = 100, y = 0, z = 0, ans;

  cin >> N >> M;

  vector<int> s(M);
  vector<int> c(M);
  vector<int> d(3, 10);

  rep(i, M) cin >> s[i] >> c[i];

  if (N == 1) {
    if (M != 0) {
      ans = c[0];
    } else {
      ans = 0;
    }

  } else if (N == 2) {
    rep(i, M) {
      if (s[i] == 1) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    if (y == 0)
      y = 10;
    ans = y + z;
  }

  else if (N == 3) {
    rep(i, M) {
      if (s[i] == 1) {
        x = 100 * c[i];
      } else if (s[i] == 2) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    ans = x + y + z;
  }

  rep(i, M) {
    if (d[s[i] - 1] == 10) {
      d[s[i] - 1] = c[i];
    } else {
      if (d[s[i] - 1] != c[i])
        ans = -1;
      break;
    }
  }

  rep(i, M) {
    if (N == 2) {
      if (s[i] == 1 && c[i] == 0)
        ans = -1;
    } else if (N == 3) {
      if (s[i] == 1 && c[i] == 0)
        ans = -1;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> kazu(n);
  int f = 0;
  int g = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      g = 1;
    }
    if (kazu.at(a - 1) != 0 && kazu.at(a - 1) != b) {
      f = -1;
    } else {
      kazu.at(a - 1) = b;
    }
  }
  if (g == 0) {
    kazu.at(1) == 1;
  }
  if (f != 0 || (n > 1 && kazu.at(0) == 0)) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      cout << kazu.at(i);
    }
    cout << endl;
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> kazu(n);
  int f = 0;
  int g = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      g = 1;
    }
    if (kazu.at(a - 1) != 0 && kazu.at(a - 1) != b) {
      f = -1;
    } else {
      kazu.at(a - 1) = b;
    }
  }
  if (g == 0 && n != 1) {
    kazu.at(0) = 1;
  }
  if (f != 0 || (n > 1 && kazu.at(0) == 0)) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      cout << kazu.at(i);
    }
    cout << endl;
  }
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a;
  rep(i, m) { cin >> a[i].first >> a[i].second; }

  rep(x, 1000) {
    int keta = 1;
    vector<int> d(1, x % 10);
    int xx = x / 10;
    while (xx) {
      keta++;
      d.push_back(xx % 10);
      xx /= 10;
    }
    reverse(d.begin(), d.end());

    if (keta == n) {
      bool ok = true;
      rep(i, m) if (d[a[i].first - 1] != a[i].second) ok = false;
      if (ok) {
        cout << x << endl;
        return 0;
      }
    } else
      continue;
  }
  cout << -1 << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  rep(i, m) { cin >> a[i].first >> a[i].second; }

  rep(x, 1000) {
    int keta = 1;
    vector<int> d(1, x % 10);
    int xx = x / 10;
    while (xx) {
      keta++;
      d.push_back(xx % 10);
      xx /= 10;
    }
    reverse(d.begin(), d.end());

    if (keta == n) {
      bool ok = true;
      rep(i, m) if (d[a[i].first - 1] != a[i].second) ok = false;
      if (ok) {
        cout << x << endl;
        return 0;
      }
    } else
      continue;
  }
  cout << -1 << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  ll n, m;
  cin >> n >> m;
  ll s[m], c[m];
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
  }
  map<ll, ll> mp;
  for (int i = 1; i <= n; ++i) {
    mp[i] = -1;
  }

  for (int i = 1; i <= m; ++i) {
    if (c[i] == 0 && s[i] == 1 && n != 1) {
      cout << -1;
      return 0;
    }
    if (mp[s[i]] != c[i] && mp[s[i]] != -1) {
      // cout<<c[i];
      cout << -1;
      return 0;
    }
    mp[s[i]] = c[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (i == 1 && mp[i] == -1 && n != 1) {
      mp[i] = 1;
    } else if (mp[i] == -1) {
      mp[i] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << mp[i];
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {

  ll n, m;
  cin >> n >> m;
  ll s[m], c[m];
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
  }
  map<ll, ll> mp;
  for (int i = 1; i <= n; ++i) {
    mp[i] = -1;
  }

  for (int i = 1; i <= m; ++i) {
    if (c[i] == 0 && s[i] == 1 && n != 1) {
      cout << -1;
      return 0;
    }
    if (mp[s[i]] != c[i] && mp[s[i]] != -1) {
      // cout<<c[i];
      cout << -1;
      return 0;
    }
    mp[s[i]] = c[i];
  }
  for (int i = 1; i <= n; ++i) {
    if (i == 1 && mp[i] == -1 && n != 1) {
      mp[i] = 1;
    } else if (mp[i] == -1) {
      mp[i] = 0;
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << mp[i];
  }
}
Problem p02761 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int n, m;
  cin >> n >> m;
  vector<pii> v;
  REP(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    v.emplace_back(s, c);
  }

  int i = n == 1 ? 0 : pow(10, n - 1);
  int e = pow(10, n);

  while (i < e) {
    string s = to_string(i);
    bool ok = true;
    REP(j, m) {
      if (s[v[j].first] != v[j].second + '0')
        ok = false;
    }
    if (ok) {
      cout << s << '\n';
      return 0;
    }
  }

  OUT(-1)

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main(void) {
  IOS int n, m;
  cin >> n >> m;
  vector<pii> v;
  REP(i, m) {
    int s, c;
    cin >> s >> c;
    s--;
    v.emplace_back(s, c);
  }

  int i = n == 1 ? 0 : pow(10, n - 1);
  int e = pow(10, n);

  while (i < e) {
    string s = to_string(i);
    bool ok = true;
    REP(j, m) {
      if (s[v[j].first] != v[j].second + '0')
        ok = false;
    }
    if (ok) {
      cout << s << '\n';
      return 0;
    }
    i++;
  }

  OUT(-1)

  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++)
    cin >> s.at(i) >> c.at(i);

  if (N == 1) {
    bool flag = true;
    for (int i = 0; i < M - 1; i++)
      if (c.at(i) != c.at(i + 1))
        flag = false;
    if (flag)
      cout << c.at(0) << endl;
    else
      cout << -1 << endl;
    return 0;
  }

  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string tmp = to_string(i);
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (tmp.at(s.at(j) - 1) != c.at(j))
        flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++)
    cin >> s.at(i) >> c.at(i);

  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else
      cout << pow(10, N - 1) << endl;
    return 0;
  }

  if (N == 1) {
    bool flag = true;
    for (int i = 0; i < M - 1; i++)
      if (c.at(i) != c.at(i + 1))
        flag = false;
    if (flag)
      cout << c.at(0) << endl;
    else
      cout << -1 << endl;
    return 0;
  }

  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    string tmp = to_string(i);
    bool flag = true;
    for (int j = 0; j < M; j++) {
      if (tmp.at(s.at(j) - 1) != c.at(j))
        flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end())
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> p(n + 1, vector<int>(0));
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    p[x].push_back(y);
  }
  // is duplicated?
  rep1(i, n) {
    if (p[i].size() < 2)
      continue;
    rep(j, p[i].size() - 1) {
      if (p[i][j] != p[i][j + 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  // is Top 0?
  if (p[1][0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  // ans
  rep1(i, n) {
    if (p[i].size() > 0)
      cout << p[i][0];
    else
      cout << 0;
  }
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define sort(A) sort(A.begin(), A.end())
#define reverse(A) reverse(A.begin(), A.end())
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> p(n + 1, vector<int>(0));
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    p[x].push_back(y);
  }
  // is duplicated?
  rep1(i, n) {
    if (p[i].size() < 2)
      continue;
    rep(j, p[i].size() - 1) {
      if (p[i][j] != p[i][j + 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  // is Top 0?
  if (p[1].size() > 0) {
    if (p[1][0] == 0) {
      if (n > 1) {
        cout << -1 << endl;
        return 0;
      }
    }
  } else {
    if (n > 1) {
      p[1].push_back(1);
    } else {
      p[1].push_back(0);
    }
  }
  // ans
  rep1(i, n) {
    if (p[i].size() > 0)
      cout << p[i][0];
    else
      cout << 0;
  }
  cout << endl;
}
Problem p02761 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> P(M);
  int i;
  if (N == 1) {
    i = 0;
  } else if (N == 2) {
    i = 10;
  } else {
    i = 100;
  }
  for (int j = 0; j < M; j++) {
    cin >> P.at(j).first >> P.at(j).second;
  }
  // cout<<1<<P.at(0).second;
  while (true) {
    string s;
    s = to_string(i);
    for (int j = 0; j < M; j++) {
      if (s.at(P.at(j).first - 1) != P.at(j).second) {
        goto PLAS;
      }
    }
    cout << i;
    break;
  PLAS:
    i++;
  }
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> P(M);
  int i;
  if (N == 1) {
    i = 0;
  } else if (N == 2) {
    i = 10;
  } else {
    i = 100;
  }
  for (int j = 0; j < M; j++) {
    cin >> P.at(j).first >> P.at(j).second;
  }
  // cout<<1<<P.at(0).second;
  while (true) {
    string s;
    s = to_string(i);
    for (int j = 0; j < M; j++) {
      if (s.at(P.at(j).first - 1) != P.at(j).second) {
        goto PLAS;
      }
    }
    cout << i;
    break;
  PLAS:
    i++;
    if (i == 1000) {
      cout << -1;
      break;
    }
  }
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> s(m);
  vector<char> c(m);

  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }

  int upper, lower;
  switch (n) {
  case 1:
    lower = 0;
    upper = 10;
    break;
  case 2:
    lower = 10;
    upper = 100;
    break;
  case 3:
    lower = 100;
    upper = 1000;
    break;
  }

  int ans = -1;
  for (int i = lower; i < upper; i++) {
    bool ok = true;
    string t = to_string(i);
    for (int j = 0; j < n; j++) {
      if (t[s[j]] != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int> s(m);
  vector<char> c(m);

  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }

  int upper, lower;
  switch (n) {
  case 1:
    lower = 0;
    upper = 10;
    break;
  case 2:
    lower = 10;
    upper = 100;
    break;
  case 3:
    lower = 100;
    upper = 1000;
    break;
  }

  int ans = -1;
  for (int i = lower; i < upper; i++) {
    bool ok = true;
    string t = to_string(i);
    for (int j = 0; j < m; j++) {
      if (t[s[j]] != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  rep(i, m) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans = -1;
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    if (n == 1 && i == 1)
      i--;
    string num = to_string(i);
    bool f = true;
    rep(j, m) {
      if (num[s[j]] != c[j])
        f = false;
    }
    if (f) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  rep(i, m) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int ans = -1;
  int st = pow(10, n - 1);
  if (n == 1)
    st = 0;
  for (int i = st; i < pow(10, n); i++) {
    string num = to_string(i);
    bool f = true;
    rep(j, m) {
      if (num[s[j]] != c[j])
        f = false;
    }
    if (f) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++)
    cin >> s[i] >> c[i];
  if (N == 1) {
    for (int i = 1; i < M; i++) {
      if (c[i] != c[0]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c[0] << endl;
    return 0;
  }
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] == -1)
      ans[s[i] - 1] = c[i];
    else {
      if (ans[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      if (i == 0)
        ans[i] = 1;
      else
        ans[i] = 0;
    }
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    if (N == 1)
      cout << 0 << endl;
    else if (N == 2)
      cout << 10 << endl;
    else
      cout << 100 << endl;
    return 0;
  }
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++)
    cin >> s[i] >> c[i];
  if (N == 1) {
    for (int i = 1; i < M; i++) {
      if (c[i] != c[0]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c[0] << endl;
    return 0;
  }
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] == -1)
      ans[s[i] - 1] = c[i];
    else {
      if (ans[s[i] - 1] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      if (i == 0)
        ans[i] = 1;
      else
        ans[i] = 0;
    }
    if (ans[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

// ABC157_C
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> S(N);
  vector<int> C(N);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }

  rep(i, 1000) {
    string str_num = to_string(i);
    if (str_num.length() != N)
      continue;

    bool flg = true;
    rep(j, M) {
      if (str_num[S.at(j) - 1] != C.at(j) + '0') {
        flg = false;
      }
    }
    if (flg) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

// ABC157_C
int main() {
  int N, M;
  cin >> N >> M;

  vector<int> S(M);
  vector<int> C(M);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
  }

  rep(i, 1000) {
    string str_num = to_string(i);
    if (str_num.length() != N)
      continue;

    bool flg = true;
    rep(j, M) {
      if (str_num[S.at(j) - 1] != C.at(j) + '0') {
        flg = false;
      }
    }
    if (flg) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
Problem p02761 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(3, -1);
  rep(i, n) {
    int d, v;
    cin >> d >> v;
    if (vec[d - 1] != -1 && vec[d - 1] != v) {
      cout << -1 << endl;
      return 0;
    }
    vec[d - 1] = v;
  }
  if (n != 1 && vec[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    int v = vec[0] != -1 ? vec[0] : 0;
    cout << v << endl;
    return 0;
  }
  int ans = 0;
  int k = n - 1;
  rep(i, n) {
    int v = (vec[i] != -1) ? vec[i] : (i == 0 ? 1 : 0);
    ans += v * pow(10, k);
    k--;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(3, -1);
  rep(i, m) {
    int d, v;
    cin >> d >> v;
    if (vec[d - 1] != -1 && vec[d - 1] != v) {
      cout << -1 << endl;
      return 0;
    }
    vec[d - 1] = v;
  }
  if (n != 1 && vec[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    int v = vec[0] != -1 ? vec[0] : 0;
    cout << v << endl;
    return 0;
  }
  int ans = 0;
  int k = n - 1;
  rep(i, n) {
    int v = (vec[i] != -1) ? vec[i] : (i == 0 ? 1 : 0);
    ans += v * pow(10, k);
    k--;
  }
  cout << ans << endl;

  return 0;
}