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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#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, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> dist(10, vector<int>(10));
  rep(i, 10) rep(j, 10) { cin >> dist[i][j]; }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int res = 0;
  rep(i, H) rep(j, W) {
    int a;
    cin >> a;
    if (a != 1) {
      res += dist[a][1];
    }
  }
  cout << res << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#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, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> dist(10, vector<int>(10));
  rep(i, 10) rep(j, 10) { cin >> dist[i][j]; }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int res = 0;
  rep(i, H) rep(j, W) {
    int a;
    cin >> a;
    if (a != -1) {
      res += dist[a][1];
    }
  }
  cout << res << endl;
  return 0;
}
Problem p03546 (C++)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> g(10, vector<int>(10));
  rep(i, 10) rep(j, 10) cin >> g[i][j];
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  rep(k, 10) rep(i, 10) rep(j, 10) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int ans = 0;
  rep(i, 10) rep(j, 10) {
    if (a[i][j] != -1)
      ans += g[a[i][j]][1];
  }
  cout << ans << endl;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> g(10, vector<int>(10));
  rep(i, 10) rep(j, 10) cin >> g[i][j];
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];

  rep(k, 10) rep(i, 10) rep(j, 10) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
  int ans = 0;
  rep(i, h) rep(j, w) {
    if (a[i][j] != -1)
      ans += g[a[i][j]][1];
  }
  cout << ans << endl;
}
Problem p03546 (C++)

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

const ll INF = 100100100100100100;

struct edge {
  // Dijkstraでは隣接リストを用いるのでfromはいらない
  // int from;
  int to;
  int c;
};

ll V, E;
const ll MAX_V = 10000;
const ll MAX_E = 10000;
void warshall(vector<vector<ll>> &dp) {

  // dpは初期化する．
  // dp[i][i]=0, dp[i][j]=(経路があればその値), (なければINF)

  for (ll k = 0; k < V; k++) {
    for (ll i = 0; i < V; i++) {
      for (ll j = 0; j < V; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}

int main() {
  V = 10;
  E = 10;
  ll H, W;
  cin >> H >> W;

  vector<vector<ll>> dp(MAX_V, vector<ll>(MAX_E, INF));
  rep(i, V) { dp[i][i] = 0; }
  rep(i, V) rep(j, E) { cin >> dp[i][j]; }

  warshall(dp);

  ll ans = 0;
  rep(i, H) rep(j, W) {
    ll tmp;
    cin >> tmp;
    if (tmp == -1)
      continue;
    ans += dp[tmp][1];
  }

  cout << ans << endl;

  return 0;
}

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

const ll INF = 100100100100100100;

struct edge {
  // Dijkstraでは隣接リストを用いるのでfromはいらない
  // int from;
  int to;
  int c;
};

ll V, E;
const ll MAX_V = 15;
const ll MAX_E = 15;
void warshall(vector<vector<ll>> &dp) {

  // dpは初期化する．
  // dp[i][i]=0, dp[i][j]=(経路があればその値), (なければINF)

  for (ll k = 0; k < V; k++) {
    for (ll i = 0; i < V; i++) {
      for (ll j = 0; j < V; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
}

int main() {
  V = 10;
  E = 10;
  ll H, W;
  cin >> H >> W;

  vector<vector<ll>> dp(MAX_V, vector<ll>(MAX_E, INF));
  rep(i, V) { dp[i][i] = 0; }
  rep(i, V) rep(j, E) { cin >> dp[i][j]; }

  warshall(dp);

  ll ans = 0;
  rep(i, H) rep(j, W) {
    ll tmp;
    cin >> tmp;
    if (tmp == -1)
      continue;
    ans += dp[tmp][1];
  }

  cout << ans << endl;

  return 0;
}
Problem p03546 (C++)

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
// const ll INF = 1LL<<60;
int INF = numeric_limits<int>::max();

int main(int, char **) {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> dist(10, vector<int>(10, INF));
  vector<int> mind;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        dist[j][k] = min(dist[j][k], dist[h][i] + dist[i][k]);
      }
    }
  }
  ll ret = 0;
  for (int i = 0; i < h * w; i++) {
    int a;
    cin >> a;
    if (a == -1)
      continue;
    else
      ret += dist[a][1];
  }
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
// const ll INF = 1LL<<60;
int INF = numeric_limits<int>::max();

int main(int, char **) {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> dist(10, vector<int>(10, INF));
  vector<int> mind;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
      }
    }
  }
  ll ret = 0;
  for (int i = 0; i < h * w; i++) {
    int a;
    cin >> a;
    if (a == -1)
      continue;
    else
      ret += dist[a][1];
  }
  cout << ret << endl;
  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, H, W, A, c[10][10];
  cin >> H >> W;
  for (int k = 0; k <= 9; k++) {
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  for (int i = 0; i <= H - 1; i++) {
    for (int j = 0; j <= W - 1; j++) {
      cin >> A;
      a += c[A >= 0 ? A : 1][1];
    }
  }
  cout << a;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, H, W, A, c[10][10];
  cin >> H >> W;
  for (int i = 0; i <= 9; i++) {
    for (int j = 0; j <= 9; j++) {
      cin >> c[i][j];
    }
  }
  for (int k = 0; k <= 9; k++) {
    for (int i = 0; i <= 9; i++) {
      for (int j = 0; j <= 9; j++) {
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  for (int i = 0; i <= H - 1; i++) {
    for (int j = 0; j <= W - 1; j++) {
      cin >> A;
      a += c[A >= 0 ? A : 1][1];
    }
  }
  cout << a;
  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<int>> A(10, vector<int>(10));
  vector<vector<int>> c(10, vector<int>(10));
  REP(i, 10) REP(j, 10) cin >> c[i][j];
  REP(i, H) REP(j, W) cin >> A[i][j];

  REP(k, 10) REP(i, 10) REP(j, 10) {
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  }

  int ans = 0;
  REP(i, H) {
    REP(j, W) {
      if (A[i][j] >= 0)
        ans += c[A[i][j]][1];
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  int H, W;
  cin >> H >> W;

  vector<vector<int>> A(H, vector<int>(W));
  vector<vector<int>> c(10, vector<int>(10));
  REP(i, 10) REP(j, 10) cin >> c[i][j];
  REP(i, H) REP(j, W) cin >> A[i][j];

  REP(k, 10) REP(i, 10) REP(j, 10) {
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  }

  int ans = 0;
  REP(i, H) {
    REP(j, W) {
      if (A[i][j] >= 0)
        ans += c[A[i][j]][1];
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll h, w;
  cin >> h >> w;
  vll c(10, vl(10));
  rep(i, 10) {
    rep(j, 10) { cin >> c[i][j]; }
  }
  vll a(h, vl(w));
  rep(i, h) {
    rep(j, w) { cin >> a[i][j]; }
  }
  for (int k = 0; k < 10; k++) {     // 経由する頂点
    for (int i = 0; i < 10; i++) {   // 始点
      for (int j = 0; j < 10; j++) { // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll sum = 0;
  rep(i, h) {
    rep(j, w) { sum += c[a[i][j]][1]; }
  }
  print(sum);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int)x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9 + 7;
const ll INF = 2e15;
template <class T> void print(const T &t) { cout << t << endl; }
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
  ll h, w;
  cin >> h >> w;
  vll c(10, vl(10));
  rep(i, 10) {
    rep(j, 10) { cin >> c[i][j]; }
  }
  vll a(h, vl(w));
  rep(i, h) {
    rep(j, w) { cin >> a[i][j]; }
  }
  for (int k = 0; k < 10; k++) {     // 経由する頂点
    for (int i = 0; i < 10; i++) {   // 始点
      for (int j = 0; j < 10; j++) { // 終点
        c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
      }
    }
  }
  ll sum = 0;
  rep(i, h) {
    rep(j, w) {
      if (a[i][j] != -1) {
        sum += c[a[i][j]][1];
      }
    }
  }
  print(sum);
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
// const int MOD = 998244353;
// const int MOD = ;
int mod(int A, int M) { return (A % M + M) % M; }
const int INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
int myctoi(char C) { return C - '0'; }
char myitoc(int N) { return '0' + N; }

signed main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c.at(i).at(j);
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        chmin(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int A;
      cin >> A;
      ans += c.at(A).at(1);
    }
  }

  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
// const int MOD = 998244353;
// const int MOD = ;
int mod(int A, int M) { return (A % M + M) % M; }
const int INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
int myctoi(char C) { return C - '0'; }
char myitoc(int N) { return '0' + N; }

signed main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> c.at(i).at(j);
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        chmin(c.at(i).at(j), c.at(i).at(k) + c.at(k).at(j));
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      int A;
      cin >> A;
      if (A != -1)
        ans += c.at(A).at(1);
    }
  }

  cout << ans << endl;
}
Problem p03546 (C++)

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

int main() {
  int h, w;
  int sum = 0;
  cin >> h >> w;

  int dist[10][10];
  int A[h][w];

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> A[i][w];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (A[i][j] != -1) {
        int x = A[i][j];
        sum += dist[x][1];
      }
    }
  }

  cout << sum << endl;
}


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

int main() {
  int h, w;
  int sum = 0;
  cin >> h >> w;

  int dist[10][10];
  int A[h][w];

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> dist[i][j];
    }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (A[i][j] != -1) {
        int x = A[i][j];
        sum += dist[x][1];
      }
    }
  }

  cout << sum << endl;
}
Problem p03546 (C++)

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

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

using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> c(10, vector<int>(10, 0));
  rep(i, 10) rep(j, 10) { cin >> c[i][j]; }
  vector<vector<int>> wall(w, vector<int>(h, 0));
  rep(i, h) rep(j, w) { cin >> wall[i][j]; }

  rep(k, 10) rep(i, 10) rep(j, 10) {
    if (c[i][j] > c[i][k] + c[k][j])
      c[i][j] = c[i][k] + c[k][j];
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (wall[i][j] >= 0)
      ans += c[wall[i][j]][1];
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

int main(void) {
  int h, w;
  cin >> h >> w;

  vector<vector<int>> c(10, vector<int>(10, 0));
  rep(i, 10) rep(j, 10) { cin >> c[i][j]; }
  vector<vector<int>> wall(h, vector<int>(w, 0));
  rep(i, h) rep(j, w) { cin >> wall[i][j]; }

  rep(k, 10) rep(i, 10) rep(j, 10) {
    if (c[i][j] > c[i][k] + c[k][j])
      c[i][j] = c[i][k] + c[k][j];
  }

  int ans = 0;
  rep(i, h) rep(j, w) {
    if (wall[i][j] >= 0)
      ans += c[wall[i][j]][1];
  }

  cout << ans << endl;
}
Problem p03546 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w;
  cin >> h >> w;

  int magic[10][10];
  int board[h][w];
  rep(i, 10) {
    rep(j, 10) { cin >> magic[i][j]; }
  }
  rep(i, h) {
    rep(j, w) { cin >> board[i][j]; }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        magic[i][j] = min(magic[i][j], magic[i][k] + magic[k][j]);
      }
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (magic[i][j] == 1 or magic[i][j] == -1)
        continue;
      ans += magic[board[i][j]][1];
    }
  }
  cout << ans << endl;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int h, w;
  cin >> h >> w;

  int magic[10][10];
  int board[h][w];
  rep(i, 10) {
    rep(j, 10) { cin >> magic[i][j]; }
  }
  rep(i, h) {
    rep(j, w) { cin >> board[i][j]; }
  }

  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        magic[i][j] = min(magic[i][j], magic[i][k] + magic[k][j]);
      }
    }
  }

  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      if (board[i][j] == 1 or board[i][j] == -1)
        continue;
      ans += magic[board[i][j]][1];
    }
  }
  cout << ans << endl;
}
Problem p03546 (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;
using P = pair<int, int>;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> jin(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int k = 0; k < 10; k++) {
      cin >> jin.at(i).at(k);
    }
  }
  vector<vector<int>> hw(H, vector<int>(W));
  for (int j = 0; j < H; j++) {
    for (int k = 0; k < W; k++) {
      cin >> hw.at(j).at(k);
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        jin.at(i).at(j) =
            min(jin.at(i).at(j), jin.at(i).at(k) + jin.at(k).at(j));
      }
    }
  }
  int sum = 0;
  for (int m = 0; m < H; m++) {
    for (int n = 0; n < W; n++) {
      int l = hw.at(m).at(n);
      sum += jin.at(l).at(1);
    }
  }
  cout << sum << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> jin(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int k = 0; k < 10; k++) {
      cin >> jin.at(i).at(k);
    }
  }
  vector<vector<int>> hw(H, vector<int>(W));
  for (int j = 0; j < H; j++) {
    for (int k = 0; k < W; k++) {
      cin >> hw.at(j).at(k);
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        jin.at(i).at(j) =
            min(jin.at(i).at(j), jin.at(i).at(k) + jin.at(k).at(j));
      }
    }
  }
  int sum = 0;
  for (int m = 0; m < H; m++) {
    for (int n = 0; n < W; n++) {
      int l = hw.at(m).at(n);
      if (l == -1) {
        continue;
      }
      sum += jin.at(l).at(1);
    }
  }
  cout << sum << endl;
}
Problem p03546 (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;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int h, w;
  const int INF = INT32_MAX >> 3;
  cin >> h >> w;
  // ベルマンフォード法
  /*
  struct edge {
      int from, to, cost;
  };
  vector<edge> G(9*9);
  rep(i,10) rep(j,10) {
      int c;
      cin >> c;
      if(i == j) continue;
      G.push_back({i,j,c});
  }
  vector<int> A;
  rep(i,h) rep(j,w) {
      int a;
      cin >> a;
      A.push_back(a);
  }
  vector<int> d_min(10);
  rep(i, 10) {
      vector<int> d(10, INF);
      d[i] = 0;
      rep(j, 10) {
          for(auto e: G) {
             if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                 d[e.to] = d[e.from] + e.cost;
             }
          }
      }
      d_min[i] = d[1];
  }
  int ans = 0;
  rep(i, A.size()) {
      if(A[i] != -1) {
          ans+=d_min[A[i]];
      }
  }
  cout << ans << endl;
  */

  // ワーシャルフロイド法
  vector<vector<int>> d(10, vector<int>(10, INF));
  rep(i, 10) rep(j, 10) cin >> d[i][j];
  vector<vector<int>> a(h * w, vector<int>(h * w));
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(k, 10) rep(i, 10) rep(j, 10) chmin(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  rep(i, h) rep(j, w) if (a[i][j] != -1) ans += d[a[i][j]][1];
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false);
  int h, w;
  const int INF = INT32_MAX >> 3;
  cin >> h >> w;
  // ベルマンフォード法
  /*
  struct edge {
      int from, to, cost;
  };
  vector<edge> G(9*9);
  rep(i,10) rep(j,10) {
      int c;
      cin >> c;
      if(i == j) continue;
      G.push_back({i,j,c});
  }
  vector<int> A;
  rep(i,h) rep(j,w) {
      int a;
      cin >> a;
      A.push_back(a);
  }
  vector<int> d_min(10);
  rep(i, 10) {
      vector<int> d(10, INF);
      d[i] = 0;
      rep(j, 10) {
          for(auto e: G) {
             if(d[e.from] != INF && d[e.from] + e.cost < d[e.to]){
                 d[e.to] = d[e.from] + e.cost;
             }
          }
      }
      d_min[i] = d[1];
  }
  int ans = 0;
  rep(i, A.size()) {
      if(A[i] != -1) {
          ans+=d_min[A[i]];
      }
  }
  cout << ans << endl;
  */

  // ワーシャルフロイド法
  vector<vector<int>> d(10, vector<int>(10, INF));
  rep(i, 10) rep(j, 10) cin >> d[i][j];
  vector<vector<int>> a(h, vector<int>(w));
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(k, 10) rep(i, 10) rep(j, 10) chmin(d[i][j], d[i][k] + d[k][j]);
  int ans = 0;
  rep(i, h) rep(j, w) if (a[i][j] != -1) ans += d[a[i][j]][1];
  cout << ans << endl;
}
Problem p03546 (C++)

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

using namespace std;
int w[10][10];
void floyd() {
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (w[i][j] > w[i][k] + w[k][j])
          w[i][j] = w[i][k] + w[k][j];
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> w[i][j];
    }
  }
  floyd();
  int tot = 0;
  int val;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> val;
      if (val != -1) {
        tot += w[val][1];
      }
    }
  }
  cout << tot << endl;
  main();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int w[10][10];
void floyd() {
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (w[i][j] > w[i][k] + w[k][j])
          w[i][j] = w[i][k] + w[k][j];
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> w[i][j];
    }
  }
  floyd();
  int tot = 0;
  int val;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> val;
      if (val != -1) {
        tot += w[val][1];
      }
    }
  }
  cout << tot << endl;
  // main();
  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;

const int MAX = 100;

int main() {
  int H, W;
  int table[10][10];
  int A[MAX][MAX];
  int ans = 0;

  cin >> H >> W;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> table[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (j == i || k == i)
          continue;
        if (table[j][k] > table[j][i] + table[i][k]) {
          table[j][k] = table[j][i] + table[i][k];
        }
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == -1)
        continue;
      ans += table[A[i][j]][1];
    }
  }

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

Fixed submission:
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;

const int MAX = 200;

int main() {
  int H, W;
  int table[10][10];
  int A[MAX][MAX];
  int ans = 0;

  cin >> H >> W;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> table[i][j];
    }
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
    }
  }

  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        if (j == i || k == i)
          continue;
        if (table[j][k] > table[j][i] + table[i][k]) {
          table[j][k] = table[j][i] + table[i][k];
        }
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == -1)
        continue;
      ans += table[A[i][j]][1];
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll, ll>

const int N = 15;

ll h, w, dp[N][N], a[N][N], res;

void solve() {
  cin >> h >> w;
  for (int i = 1; i <= 10; i++) {
    for (int j = 1; j <= 10; j++)
      cin >> dp[i][j];
  }
  for (int k = 1; k <= 10; k++) {
    for (int i = 1; i <= 10; i++) {
      for (int j = 1; j <= 10; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  res = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
      if (a[i][j] == -1)
        continue;
      res += dp[a[i][j] + 1][2];
    }
  }
  cout << res << "\n";
}

int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef localProject
  freopen("in.txt", "r", stdin);
#endif
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll, ll>

const int N = 210;

ll h, w, dp[N][N], a[N][N], res;

void solve() {
  cin >> h >> w;
  for (int i = 1; i <= 10; i++) {
    for (int j = 1; j <= 10; j++)
      cin >> dp[i][j];
  }
  for (int k = 1; k <= 10; k++) {
    for (int i = 1; i <= 10; i++) {
      for (int j = 1; j <= 10; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  res = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> a[i][j];
      if (a[i][j] == -1)
        continue;
      res += dp[a[i][j] + 1][2];
    }
  }
  cout << res << "\n";
}

int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef localProject
  freopen("in.txt", "r", stdin);
#endif
  solve();
  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#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<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  int h, w;
  cin >> h >> w;
  int n = 10;
  VVI d(n, VI(n));
  REP(i, n) REP(j, n) cin >> d[i][j];

  REP(i, n) REP(j, n) REP(k, n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

  int ans = 0;
  REP(i, h) REP(j, w) {
    int x;
    cin >> x;
    ans += d[x][1];
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#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<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

int main() {
  int h, w;
  cin >> h >> w;
  int n = 10;
  VVI d(n, VI(n));
  REP(i, n) REP(j, n) cin >> d[i][j];

  REP(i, n) REP(j, n) REP(k, n) d[j][k] = min(d[j][k], d[j][i] + d[i][k]);

  int ans = 0;
  REP(i, h) REP(j, w) {
    int x;
    cin >> x;
    if (x >= 0)
      ans += d[x][1];
  }
  cout << ans << endl;

  return 0;
}
Problem p03546 (C++)

Buggy submission (status: Runtime Error):
/**
    In the name of Allah, the Most Gracious, the Most Merciful.
**/

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

typedef long long ll;

int matrix[11][11];
int cell[11][11];
int n, m;

int main() {
#ifdef _OFFLINE_
  freopen("in.txt", "r", stdin);
#endif /// _OFFLINE_

  cin >> n >> m;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> matrix[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (matrix[i][j] > matrix[i][k] + matrix[k][j]) {
          matrix[i][j] = matrix[i][k] + matrix[k][j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> cell[i][j];
      if (cell[i][j] != abs(1)) {
        ans += matrix[cell[i][j]][1];
      }
    }
  }

  cout << ans << "\n";

  return 0;
}


Fixed submission:
/**
    In the name of Allah, the Most Gracious, the Most Merciful.
**/

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

typedef long long ll;

int matrix[11][11];
int cell[205][205];
int n, m;

int main() {
#ifdef _OFFLINE_
  freopen("in.txt", "r", stdin);
#endif /// _OFFLINE_

  cin >> n >> m;
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> matrix[i][j];
    }
  }
  for (int k = 0; k < 10; k++) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (matrix[i][j] > matrix[i][k] + matrix[k][j]) {
          matrix[i][j] = matrix[i][k] + matrix[k][j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> cell[i][j];
      if (cell[i][j] != abs(1)) {
        ans += matrix[cell[i][j]][1];
      }
    }
  }

  cout << ans << "\n";

  return 0;
}
Problem p03547 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x, y, z;
  cin >> x >> y >> z;
  x -= z;
  int cnt = 0;
  while (x >= y + z) {
    cnt++;
    x -= (y + z);
  }
  cout << cnt;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  if (a < b)
    cout << "<";
  if (a == b)
    cout << "=";
  if (a > b)
    cout << ">";
}
Problem p03547 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  while (1) {
    char a, b;
    scanf("%c %c", &a, &b);
    getchar();
    if (a - b > 0) {
      printf(">\n");
    }
    if (a - b < 0) {
      printf("<\n");
    }
    if (a - b == 0) {
      printf("=\n");
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  char a, b;
  while (~scanf("%c %c", &a, &b)) {
    getchar();
    if (a - b > 0) {
      printf(">\n");
    }
    if (a - b < 0) {
      printf("<\n");
    }
    if (a - b == 0) {
      printf("=\n");
    }
  }
  return 0;
}
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
x, y = map(int, input().split())
if x < y:
    print("<")
elif x > y:
    print(">")
else:
    print("=")


Fixed submission:
x, y = input().split()
if x < y:
    print("<")
elif x > y:
    print(">")
else:
    print("=")
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
import sys

input = sys.stdin.readline


def main():
    x, y = map(int, input().split())
    table = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6}
    x = table[x]
    y = table[y]
    if x < y:
        print("<")
    elif x == y:
        print("=")
    else:
        print(">")


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline


def main():
    x, y = input().split()
    table = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5, "F": 6}
    x = table[x]
    y = table[y]
    if x < y:
        print("<")
    elif x == y:
        print("=")
    else:
        print(">")


if __name__ == "__main__":
    main()
Problem p03547 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
char a, b;
int main() {
  scanf("%c", &a, &b);
  printf("%s", a > b ? '>' : (a == b ? '=' : '<'));
  return 0;
}


Fixed submission:
#include <stdio.h>
char a, b;
int main() {
  scanf("%c %c", &a, &b);
  printf("%c", a > b ? '>' : (a == b ? '=' : '<'));
  return 0;
}
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
x = input()
y = input()

if x < y:
    print("<")
elif y < x:
    print(">")
else:
    print("=")


Fixed submission:
a = list(input())
x = a[0]
y = a[2]

if x < y:
    print("<")
elif y < x:
    print(">")
else:
    print("=")
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
x, y = map(ord(), input().split())
if x == y:
    print("=")
elif x < y:
    print("<")
else:
    print(">")


Fixed submission:
x, y = map(ord, input().split())
if x == y:
    print("=")
elif x < y:
    print("<")
else:
    print(">")
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
X, Y = map(int, input().split())
X = ord(X)
Y = ord(Y)
if X < Y:
    print("<")
elif X > Y:
    print(">")
else:
    print("=")


Fixed submission:
X, Y = input().split()
X = ord(X)
Y = ord(Y)
if X < Y:
    print("<")
elif X > Y:
    print(">")
else:
    print("=")
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
x, y = map(int, input().split())
if x < y:
    print("<")
elif x > y:
    print(">")
else:
    print("=")


Fixed submission:
x, y = map(ord, input().split())
if x < y:
    print("<")
elif x > y:
    print(">")
else:
    print("=")
Problem p03547 (Python)

Buggy submission (status: Runtime Error):
X, Y = map(int, input().split(" "))
print("<" if X < Y else "=" if X == Y else ">")


Fixed submission:
X, Y = input().split(" ")
print("<" if X < Y else "=" if X == Y else ">")
Problem p03548 (C++)

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

int main() {
  int x, y, z;
  if (x < y + z * 2)
    cout << 0 << endl;
  else {
    x -= y + z * 2;
    cout << 1 + x / (y + z) << endl;
  }
}

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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  if (x < y + z * 2)
    cout << 0 << endl;
  else {
    x -= y + z * 2;
    cout << 1 + x / (y + z) << endl;
  }
}
Problem p03548 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

int main() {
  int X, Y, Z, S;
  scanf("%d %d %d", X, Y, Z);
  S = (X - Z) / (Y + Z);
  printf("%d", S);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>

int main() {
  int X, Y, Z, S;
  scanf("%d %d %d", &X, &Y, &Z);
  S = (X - Z) / (Y + Z);
  printf("%d", S);
}
Problem p03548 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int a, b, c;
int main() {
  scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", (a - c) / (b - c));
  return 0;
}

Fixed submission:
#include <cstdio>
int n, m, k;
signed main() {
  return scanf("%d%d%d", &n, &m, &k), printf("%d\n", (n - k) / (m + k)), 0;
}
Problem p03548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
int main() {
  int x, y, z, n;
  while (y + 2 * z <= x) {
    scanf("%d%d%d", &x, &y, &z);
    n = (x - z) / (y + z);
    printf("%d", n);
  }
  return 0;
}


Fixed submission:
#include <cstdio>
int main() {
  int x, y, z, n;
  scanf("%d%d%d", &x, &y, &z);
  n = (x - z) / (y + z);
  printf("%d", n);
  return 0;
}
Problem p03548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

int main(void) {
  int X, Y, Z;
  do {
    scanf("%d%d%d", &X, &Y, &Z);
  } while (X < 1 || X > 100000 || Y < 1 || Y > 100000 || Z < 1 || Z > 100000 ||
           Y + Z * 2 >= X);

  printf("%d\n", (X - Z) / (Y + Z));

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int X, Y, Z;
  do {
    scanf("%d%d%d", &X, &Y, &Z);
  } while (X < 1 || X > 100000 || Y < 1 || Y > 100000 || Z < 1 || Z > 100000 ||
           Y + Z * 2 > X);

  printf("%d\n", (X - Z) / (Y + Z));

  return 0;
}
Problem p03548 (C++)

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

long long a, b, c;

int main() {
  cout << (a - c) / (b + c);
  return 0;
}

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

long long a, b, c;

int main() {
  ios::sync_with_stdio(0);
  cin >> a >> b >> c;
  cout << (a - c) / (b + c);
  return 0;
}
Problem p03548 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
  long long a, b, c, d;
  while (scanf("%lld %lld %lld", &a, &b, &c)) {
    d = ceil(a / (b + c)) - 1;
    printf("%lld\n", d);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main() {
  long long a, b, c, d;
  while (~scanf("%lld %lld %lld", &a, &b, &c)) {
    d = (a / (b + c));
    if ((b + c) * d + c <= a)
      printf("%lld\n", d);
    if ((b + c) * d + c > a)
      printf("%lld\n", d - 1);
  }
}
Problem p03548 (C++)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int sum;
  sum = (a - c) / (b + c);

  cout << sum << endl;
  return sum;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int sum;
  sum = (a - c) / (b + c);

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << (1900 * n + 100 * (m - n)) / (n - 1) / (n - 1);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  cout << (1900 * m + 100 * (n - m)) * (pow(2, m)) << endl;
}
Problem p03550 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main() {
  ll N, Z, W;
  cin >> N >> Z >> W;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  cout << max(abs(A.at(N - 1) - W), abs(A.at(N - 1) - A.at(N - 2))) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main() {
  ll N, Z, W;
  cin >> N >> Z >> W;
  vector<ll> A(N);
  rep(i, N) cin >> A.at(i);
  if (N == 1)
    cout << abs(A.at(N - 1) - W) << endl;
  else
    cout << max(abs(A.at(N - 1) - W), abs(A.at(N - 1) - A.at(N - 2))) << endl;
}
Problem p03550 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

#define ll long long

ll n;
ll a[2001];

ll abc(ll x, ll y) {
  if (x - y > 0) {
    return x - y;
  }
  return y - x;
}

ll solve(ll i, ll z, ll w, ll part) {
  // (i + 1) ~ n個見る
  if (i == n) {
    return abc(z, w);
  }
  ll max = -1;
  ll min = -1;
  for (ll j = i + 1; j <= n; j++) {
    // jまで取る
    ll sub;
    if (part == 0) {
      sub = solve(j, a[j], w, 1);
    } else {
      sub = solve(j, z, a[j], 0);
    }
    if (min == -1 || min > sub) {
      min = sub;
    }
    if (max < sub) {
      max = sub;
    }
  }
  if (part == 0) {
    return max;
  }
  return min;
}

int main() {
  ll z, w;
  cin >> n >> z >> w;
  a[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << solve(0, z, w, 0) << endl;
}

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

#define ll long long

ll n;
ll a[2001];

ll abc(ll x, ll y) {
  if (x - y > 0) {
    return x - y;
  }
  return y - x;
}

ll solve(ll i, ll z, ll w, ll part) {
  // (i + 1) ~ n個見る
  if (i == n) {
    return abc(z, w);
  }
  ll max = -1;
  ll min = -1;
  for (ll j = i + 1; j <= n; j++) {
    // jまで取る
    ll sub;
    if (part == 0) {
      sub = solve(j, a[j], w, 1);
    } else {
      sub = solve(j, z, a[j], 0);
    }
    if (min == -1 || min > sub) {
      min = sub;
    }
    if (max < sub) {
      max = sub;
    }
  }
  if (part == 0) {
    return max;
  }
  return min;
}

int main() {
  ll z, w;
  cin >> n >> z >> w;
  a[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
  }
  // all とる時
  int all = abc(a[n], w);
  // all 手前
  int sub = -1;
  if (n > 1) {
    sub = abc(a[n - 1], a[n]);
  }
  if (all > sub) {
    cout << all << endl;
  } else {
    cout << sub << endl;
  }
}
Problem p03550 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <vector>
#define INF 1e9
using namespace std;
int main(void) {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  return max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w));
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <vector>
#define INF 1e9
using namespace std;
int main(void) {
  int n, z, w;
  cin >> n >> z >> w;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  if (n >= 2) {
    cout << max(abs(a[n - 1] - a[n - 2]), abs(a[n - 1] - w)) << endl;
  } else {
    cout << abs(a[n - 1] - w);
  }
  return 0;
}
Problem p03550 (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;
const int MOD = 1000000007;
int main() {
  int N, Z, W;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  if (N == 1) {
    cout << abs(a[0] - W) << endl;
    return 0;
  }
  cout << max(abs(a[N - 1] - W), abs(a[N - 2] - a[N - 1])) << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main() {
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  if (N == 1) {
    cout << abs(a[0] - W) << endl;
    return 0;
  }
  cout << max(abs(a[N - 1] - W), abs(a[N - 2] - a[N - 1])) << endl;

  return 0;
}