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

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
const int INF = (1 << 25);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int main() {

  int n;
  cin >> n;
  while (n--) {
    int cnt = 0;
    string s;
    map<int, char> m;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (isalpha(s[i]))
        m[cnt] = s[i];
      else if (s[i] == '<')
        cnt--;
      else if (s[i] == '>')
        cnt++;
    }

    for (map<int, char>::iterator it = m.begin(); it != m.end(); it++) {
      cout << (*it).second;
    }

    cout << endl;
  }
}

Error: WA

Fixed submission:

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pii> pip;
const int INF = (1 << 25);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

int main() {

  int n;
  int data[1000][2];
  int now_train;

  cin >> n;
  while (n--) {
    for (int i = 0; i < 30; i++)
      data[i][0] = data[i][1] = -1;
    char c;
    cin >> c;
    now_train = abs('a' - c);

    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i += 3) {
      if (s[i] == '-') {
        data[now_train][1] = abs('a' - s[i + 2]);
        data[abs('a' - s[i + 2])][0] = now_train;
      } else {
        data[now_train][0] = abs('a' - s[i + 2]);
        data[abs('a' - s[i + 2])][1] = now_train;
      }
      now_train = abs('a' - s[i + 2]);
    }

    string ans;
    int left, right;
    for (int i = 0; i < 26; i++) {
      if (data[i][0] == -1 && data[i][1] != -1) {
        left = i;
        ans += 'a' + left;
      } else if (data[i][1] == -1 && data[i][0] != -1) {
        right = i;
      }
    }
    while (left != right) {
      ans += 'a' + data[left][1];
      left = data[left][1];
    }
    cout << ans << endl;
  }
}
Problem p00130 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;
char T[1000000];
int length = 500000, n;
string S;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int i = 0; i < 1000000; i++) {
      T[i] = ' ';
    }
    length = 500000;
    cin >> S;
    for (int i = 0; i <= S.size() / 3; i++) {
      T[length] = S[i * 3];
      if (S.size() != i) {
        if (S[i * 3 + 1] == '-') {
          length++;
        } else {
          length--;
        }
      }
    }
    for (int i = 0; i < 1000000; i++) {
      if (T[i] != ' ') {
        cout << T[i];
      }
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
char T[2000000];
int length = 1000000, n;
string S;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int i = 0; i < 2000000; i++) {
      T[i] == ' ';
    }
    length = 1000000;
    cin >> S;
    for (int i = 0; i <= S.size() / 3; i++) {
      T[length] = S[i * 3];
      if (S.size() != i) {
        if (S[i * 3 + 1] == '-') {
          length++;
        } else {
          length--;
        }
      }
    }
    for (int i = 0; i < 2000000; i++) {
      if (T[i] != ' ') {
        cout << T[i];
      }
    }
    cout << endl;
  }
}
Problem p00130 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void) {
  int n;
  cin >> n;

  while (n--) {
    string in, res;
    cin >> in;
    res = in.at(0);

    for (int i = 3; i < in.size(); i += 3) {
      string cur = in.substr(i, 1);

      if (~res.find(cur))
        continue;
      switch (in.at(i - 2)) {
      case '-':
        res = res + cur;
        break;
      case '<':
        res = cur + res;
        break;
      }
    }
    cout << res << endl;
  }

  return 0;
}

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


Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define COUNT(i, n) for (int i = 1; i <= n; i++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for (ITER(c) it = (c).begin(); it != (c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void) {
  int n;
  cin >> n;

  while (n--) {
    string in, res;
    cin >> in;
    res = in.at(0);

    COUNT(i, in.size() - 3) {
      i += 2;
      string cur = in.substr(i, 1);

      if (~res.find(cur))
        continue;
      switch (in.at(i - 2)) {
      case '-':
        res = res + cur;
        break;
      case '<':
        res = cur + res;
        break;
      }
    }
    cout << res << endl;
  }

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

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

int main() {
  int N;
  cin >> N;
  while (N--) {
    string str;
    cin >> str;
    string ans;
    ans += str[0];
    int corsor = 0;
    for (int i = 1; i * 3 + 1 <= str.size(); i++) {
      auto pre =
          string(str.begin() + (i - 1) * 3 + 1, str.begin() + (i - 1) * 3 + 3);
      if (pre == "<-")
        corsor--;
      else
        corsor++;

      if (corsor < 0)
        corsor = 0, ans = str[i * 3] + ans;
      if (corsor >= ans.size())
        ans += str[i * 3];
    }
    cout << ans << endl;
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int c(string str, int dir, int cursor, char a) {
  for (int i = cursor; 0 <= i && i < str.size(); i += dir) {
    if (a == str[i]) {
      return i;
    }
  }

  return cursor + dir;
}

int main() {
  string str;
  int n;
  cin >> n;
  while (n--) {
    cin >> str;
    int cursor = 0;
    string res = "";

    res += str[0];

    for (int i = 1; i < str.size() - 2; i += 3) {
      if (str[i] == '-') {
        cursor = c(res, 1, cursor, str[i + 2]);
        if (res.size() == cursor) {
          res += str[i + 2];
        }
      } else if (str[i] == '<') {
        cursor--;
        cursor = c(res, -1, cursor, str[i + 2]);
        if (cursor < 0) {
          res = str[i + 2] + res;
          cursor = 0;
        }
      }
    }

    cout << res << endl;
  }

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

#include <iostream>
using namespace std;
int I, flg;
int t[10][10], u[10][10];
int ans[10][10];
void check();
void dfs(int);
void compute(int, int);
int main() {
  cin >> I;
  while (I--) {
    flg = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        cin >> t[i][j];
        u[i][j] = t[i][j];
        ans[i][j] = 0;
      }
    }
    dfs(0);
  }
  return 0;
}

void dfs(int x) {
  if (flg)
    return;
  if (x == 10) {
    check();
  } else {
    ans[0][x] = 0;
    dfs(x + 1);
    if (flg)
      return;
    ans[0][x] = 1;
    dfs(x + 1);
  }
}

void check() {
  if (flg)
    return;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      t[i][j] = u[i][j];

  for (int i = 0; i < 10; i++)
    if (ans[0][i] == 1)
      compute(0, i);

  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      ans[i][j] = 0;
      if (t[i - 1][j] == 1) {
        ans[i][j] = 1;
        compute(i, j);
      }
    }
  }
  /*
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(j)cout<<' ';
      cout<<t[i][j];
    }
    cout<<endl;
  }
  */
  int cnt = 0;
  for (int i = 0; i < 10; i++)
    cnt += t[9][i];
  if (cnt == 0) {
    flg = 1;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (j)
          cout << ' ';
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
}

void compute(int y, int x) {
  t[y][x] = (t[y][x] * -1) + 1;
  if (y > 0)
    t[y - 1][x] = (t[y - 1][x] * -1) + 1;
  if (x > 0)
    t[y][x - 1] = (t[y][x - 1] * -1) + 1;
  if (y < 9)
    t[y + 1][x] = (t[y + 1][x] * -1) + 1;
  if (x < 9)
    t[y][x + 1] = (t[y][x + 1] * -1) + 1;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int I, flg;
int t[10][10], u[10][10];
int ans[10][10];
void check();
void dfs(int);
void compute(int, int);
int main() {
  cin >> I;
  while (I--) {
    flg = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        cin >> t[i][j];
        u[i][j] = t[i][j];
        ans[i][j] = 0;
      }
    }
    dfs(0);
  }
  return 0;
}

void dfs(int x) {
  if (flg)
    return;
  if (x == 10)
    check();
  ans[0][x] = 0;
  dfs(x + 1);
  ans[0][x] = 1;
  dfs(x + 1);
}

void check() {
  if (flg)
    return;
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      t[i][j] = u[i][j];
  for (int i = 0; i < 10; i++)
    if (ans[0][i])
      compute(0, i);
  for (int i = 1; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      if (t[i - 1][j] == 1) {
        ans[i][j] = 1;
        compute(i, j);
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < 10; i++)
    cnt += t[9][i];
  if (cnt == 0) {
    flg = 1;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (j)
          cout << ' ';
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
}

void compute(int y, int x) {
  t[y][x] = !t[y][x];
  if (y > 0)
    t[y - 1][x] = !t[y - 1][x];
  if (x > 0)
    t[y][x - 1] = !t[y][x - 1];
  if (y < 9)
    t[y + 1][x] = !t[y + 1][x];
  if (x < 9)
    t[y][x + 1] = !t[y][x + 1];
}
Problem p00131 (C++) — buggy submission, verdict: Runtime Error

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

void mark(int mp[10][10], int y, int x) {
  int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx < 0 || ny < 0 || nx >= 10 || ny >= 10)
      continue;
    mp[ny][nx] = !mp[ny][nx];
  }
  mp[y][x] = !mp[y][x];
}

bool check(int mp[10][10]) {
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (mp[i][j])
        return 0;
  return 1;
}

int main() {
  int q;
  cin >> q;
  while (q--) {
    int mp[10][10], b[10][10];
    for (int i = 0; i < 10; i++)
      for (int j = 0; j < 10; j++)
        cin >> mp[i][j], b[i][j] = mp[i][j];

    int ans[10][10] = {};
    for (int i = 0; !check(mp); i++) {
      for (int j = 0; j < 10; j++)
        for (int k = 0; k < 10; k++)
          mp[j][k] = b[j][k];
      for (int j = 0; j < 10; j++)
        for (int k = 0; k < 10; k++)
          b[j][k] = mp[j][k];

      for (int j = 0; j < 10; j++)
        if ((ans[0][j] = ((i >> j) % 2)))
          mark(mp, 0, j);
      for (int j = 1; j < 10; j++)
        for (int k = 0; k < 10; k++)
          if ((ans[j][k] = mp[j - 1][k]))
            mark(mp, j, k);
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (j)
          cout << " ";
        cout << ans[i][j];
        assert(ans[i][j] == 0 || ans[i][j] == 1);
      }
      cout << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

void mark(int mp[10][10], int y, int x) {
  int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx < 0 || ny < 0 || nx >= 10 || ny >= 10)
      continue;
    mp[ny][nx] = !mp[ny][nx];
  }
  mp[y][x] = !mp[y][x];
}

bool check(int mp[10][10]) {
  for (int i = 0; i < 10; i++)
    for (int j = 0; j < 10; j++)
      if (mp[i][j])
        return 0;
  return 1;
}

int main() {
  int q;
  cin >> q;
  while (q--) {

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

    int ans[10][10];
    for (int i = 0; i < (1 << 10) && !check(mp); i++) {
      for (int j = 0; j < 10; j++)
        ans[0][i] = (1 & (1 << j));
      for (int j = 1; j < 10; j++)
        for (int k = 0; k < 10; k++)
          if ((ans[j][k] = mp[j - 1][k]))
            mark(mp, j, k);
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        if (j)
          cout << " ";
        cout << ans[i][j];
      }
      cout << endl;
    }
  }

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

#include <cstring>
#include <iostream>
using namespace std;

int n, s, y, x, i;
int d[12][12], b[12][12], a[12][12];
int dx[] = {0, 0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0, 0};

void flip(int x, int y) {
  a[y][x] = 1;
  for (int i = 0; i < 5; i++) {
    b[y + dy[i]][x + dx[i]] = 1 - b[y + dy[i]][x + dx[i]];
  }
}

int main() {
  cin >> n;
  while (n--) {
    for (y = 1; y <= 10; y++)
      for (x = 1; x <= 10; x++) {
        cin >> d[y][x];
      }
    for (i = 0; i < 1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(d));

      for (y = 1, x = 1; x <= 10; x++) {
        if ((i >> (x - 1)) & 1)
          flip(x, y);
      }

      for (y = 2; y <= 10; y++)
        for (x = 1; x <= 10; x++) {
          if (b[y - 1][x])
            flip(x, y);
        }

      for (y = 10, x = 1, s = 0; x <= 10; x++) {
        s += b[y][x];
      }

      if (s == 0)
        break;
    }

    for (y = 1; y <= 10; y++) {
      for (x = 1; x <= 10; x++) {
        cout << a[y][x] << (x == 10 ? "" : " ");
      }
      cout << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;

int n, s, y, x, i;
int d[12][12], b[12][12], a[12][12];
int dx[] = {0, 0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0, 0};

void flip(int x, int y) {
  a[y][x] = 1;
  for (i = 0; i < 5; i++) {
    b[y + dy[i]][x + dx[i]] = 1 - b[y + dy[i]][x + dx[i]];
  }
}

int main() {
  cin >> n;
  while (n--) {
    for (y = 1; y <= 10; y++)
      for (x = 1; x <= 10; x++) {
        cin >> d[y][x];
      }

    for (i = 0; i < 1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(d));

      for (y = 1, x = 1; x <= 10; x++) {
        if ((i >> (x - 1)) & 1)
          flip(x, y);
      }

      for (y = 2; y <= 10; y++)
        for (x = 1; x <= 10; x++) {
          if (b[y - 1][x])
            flip(x, y);
        }

      for (y = 10, x = 1, s = 0; x <= 10; x++) {
        s += b[y][x];
      }

      if (s == 0)
        break;
    }

    for (y = 1; y <= 10; y++) {
      for (x = 1; x <= 10; x++) {
        cout << a[y][x] << (x == 10 ? "" : " ");
      }
      cout << endl;
    }
  }
}
Problem p00131 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

bool grid[10][10];

void rev(int y, int x) {
  int dy[] = {1, 0, -1, 0, 0}, dx[] = {0, 1, 0, -1, 0};

  for (int i = 0; i < 5; i++) {
    int sy = y + dy[i], sx = x + dx[i];
    if (sy < 0 || sx < 0 || sy >= 10 || sx >= 10)
      continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main() {
  int t;
  bool tmp[10][10];
  int ans[10][10];

  cin >> t;
  while (t--) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        cin >> grid[i][j];
        tmp[i][j] = grid[i][j];
      }
    }

    for (int i = 0; i < (1 << 10); i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++)
          grid[j][k] = tmp[j][k];
      }

      for (int j = 0; j < 10; j++) {
        if (i & (1 << j)) {
          rev(0, j);
          ans[0][j] = 1;
        } else
          ans[0][j] = 0;
      }

      for (int j = 1; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (grid[j - 1][k]) {
            rev(j, k);
            ans[j][k] = 1;
          } else
            ans[j][k] = 0;
        }
      }

      bool f = false;
      for (int j = 0; j < 10; j++)
        f |= grid[9][j];
      if (!f)
        break;
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 9; j++)
        cout << ans[i][j] << " ";
      cout << ans[i][9] << endl;
    }
    // if(t)cout << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

bool grid[10][10];

void rev(int y, int x) {
  int dy[] = {1, 0, -1, 0, 0}, dx[] = {0, 1, 0, -1, 0};

  for (int i = 0; i < 5; i++) {
    int sy = y + dy[i], sx = x + dx[i];
    if (sy < 0 || sx < 0 || sy > 10 || sx > 10)
      continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main() {
  int t;
  bool tmp[10][10];
  bool ans[10][10];

  cin >> t;
  while (t--) {
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        cin >> grid[i][j];
        tmp[i][j] = grid[i][j];
      }
    }

    for (int i = 0; i < (1 << 10); i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++)
          grid[i][j] = tmp[i][j];
      }

      for (int j = 0; j < 10; j++) {
        if (i & (1 << j)) {
          rev(0, j);
          ans[0][j] = true;
        } else
          ans[0][j] = false;
      }

      for (int j = 1; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          if (grid[j - 1][k]) {
            rev(j, k);
            ans[j][k] = true;
          } else
            ans[j][k] = false;
        }
      }

      bool f = false;
      for (int j = 0; j < 10; j++)
        f |= grid[9][j];
      if (!f)
        break;
    }

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 9; j++)
        cout << ans[i][j] << " ";
      cout << ans[i][9] << endl;
    }
  }
}
Problem p00131 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

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

using namespace std;

int main() {
  int S3[1024];
  rep(S, 1024) {
    int stat = 0;
    rep(j, 10) if (S & (1 << j)) {
      stat ^= 1 << j;
      if (j > 0)
        stat ^= 1 << (j - 1);
      if (j < 9)
        stat ^= 1 << (j + 1);
    }
    S3[S] = stat;
  }

  int T;
  scanf("%d", &T);
  while (T--) {
    int org[10] = {};
    rep(i, 10) rep(j, 10) {
      int tmp;
      scanf("%d", &tmp);
      org[i] |= tmp << j;
    }

    int ans = -1;
    rep(S, 1024) {
      int grid[10];
      rep(i, 10) grid[i] = org[i];

      grid[0] ^= S3[S];
      grid[1] ^= S;
      for (int i = 1; i < 10; i++) {
        int pttn = grid[i - 1];
        grid[i - 1] = 0;
        grid[i] ^= S3[pttn];
        if (i < 9)
          grid[i + 1] ^= pttn;
      }

      if (grid[9] == 0) {
        ans = S;
        break;
      }
    }
    if (ans == -1)
      while (1)
        ;

    rep(j, 10) printf("%d%c", !!(ans & (1 << j)), j < 9 ? ' ' : '\\n');
    org[0] ^= S3[ans];
    org[1] ^= ans;
    for (int i = 1; i < 10; i++) {
      int pttn = org[i - 1];
      org[i - 1] = 0;
      org[i] ^= S3[pttn];
      if (i < 10)
        org[i + 1] ^= pttn;
      rep(j, 10) printf("%d%c", !!(pttn & (1 << j)), j < 9 ? ' ' : '\\n');
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>

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

using namespace std;

int main() {
  int S3[1024];
  rep(S, 1024) {
    int stat = 0;
    rep(j, 10) if (S & (1 << j)) {
      stat ^= 1 << j;
      if (j > 0)
        stat ^= 1 << (j - 1);
      if (j < 9)
        stat ^= 1 << (j + 1);
    }
    S3[S] = stat;
  }

  int T;
  scanf("%d", &T);
  while (T--) {
    int org[10] = {};
    rep(i, 10) rep(j, 10) {
      int tmp;
      scanf("%d", &tmp);
      org[i] |= tmp << j;
    }

    int ans = -1;
    rep(S, 1024) {
      int grid[10];
      rep(i, 10) grid[i] = org[i];

      grid[0] ^= S3[S];
      grid[1] ^= S;
      for (int i = 1; i < 10; i++) {
        int pttn = grid[i - 1];
        grid[i - 1] = 0;
        grid[i] ^= S3[pttn];
        if (i < 10)
          grid[i + 1] ^= pttn;
      }

      if (grid[9] == 0) {
        ans = S;
        break;
      }
    }
    if (ans == -1)
      while (1)
        ;

    rep(j, 10) printf("%d%c", (bool)(ans & (1 << j)), j < 9 ? ' ' : '\\n');
    org[0] ^= S3[ans];
    org[1] ^= ans;
    for (int i = 1; i < 10; i++) {
      int pttn = org[i - 1];
      org[i - 1] = 0;
      org[i] ^= S3[pttn];
      if (i < 10)
        org[i + 1] ^= pttn;
      rep(j, 10) printf("%d%c", (bool)(pttn & (1 << j)), j < 9 ? ' ' : '\\n');
    }
  }

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

#include <cstring>
#include <iostream>
using namespace std;

char map[8][9];

void rotate() {
  char bM[8][9];
  memcpy(bM, map, 72);
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      map[i][j] = bM[7 - j][i];
    }
  }
}

void showmap() {
  for (int i = 0; i < 8; i++) {
    printf("%s\\n", map[i]);
  }
}
int main(void) {
  for (int j = 0; j <= 7; j++) {
    cin >> map[j];
  }
  printf("90\\n");
  rotate();
  showmap();
  printf("180\\n");
  rotate();
  showmap();
  printf("270\\n");
  rotate();
  showmap();
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  char map[8][8];
  for (int j = 0; j <= 7; j++) {
    scanf("%s", map[j]);
  }
  printf("90\\n");
  for (int i = 7; i >= 0; i--) {
    for (int j = 0; j <= 7; j++) {
      printf("%c", map[i][j]);
    }
    printf("\\n");
  }
  printf("180\\n");
  for (int i = 7; i >= 0; i--) {
    for (int j = 7; j >= 0; j--) {
      printf("%c", map[i][j]);
    }
    printf("\\n");
  }
  printf("270\\n");
  for (int i = 0; i <= 7; i++) {
    for (int j = 7; j >= 0; j--) {
      printf("%c", map[i][j]);
    }
    printf("\\n");
  }
  return 0;
}
Problem p00134 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  long long int n, a, s, i;
  cin >> n;
  for (i = s = 0; i < n; i++) {
    cin >> a;
    s += a;
  }
  cout << s / n << endl;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m = 0, s = 0, i;
  for (i = 0; i < n; i++) {
    cin >> m;
    s += m;
  }
  cout << s / n << endl;
  return 0;
}
Problem p00134 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
int main() {
  int n, t;
  long long res = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &t);
    res += t;
  }
  printf("%d\\n", (int)(res / n));
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
int main() {
  long long n, res = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int t;
    scanf("%d", &t);
    res += t;
  }
  printf("%d\\n", (int)(res / n));
  return 0;
}
Problem p00134 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i, b, s[100010];
  long long int av = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    av = s[i] + av;
  }
  cout << av / n << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, s[1000], i, j, b;
  long long int av = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s[i];
    av = s[i] + av;
  }
  cout << av / n << endl;
}