Problem p00730 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define INF 1 << 27
#define all(n) n.begin(), n.end()
#define insert(a, b, c, d) PP(P(a, b), P(c, d))
#define F first
#define S second
#define pb push_back
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef long long ll;
typedef unsigned long long ull;

class Solve {
private:
  int n, w, d;
  vector<P> info;

public:
  Solve(int _n, int _w, int _d) : n(_n), w(_w), d(_d) { info.pb(P(w, d)); }
  ~Solve() { info.clear(); }

  int getN() { return n; }

  int getW() { return w; }

  int getD() { return d; }

  void printAll() {
    cout << "n = " << n << ",w = " << w << ",d = " << d << endl;
    cout << "info---" << endl;
    rep(i, info.size()) {
      cout << i << " - th : " << info[i].F << "," << info[i].S << endl;
    }
    cout << "end---" << endl;
  }

  void getAns() { sortVector(info); }

  void cutInfo(int p, int s) {
    P store = info[p];
    eraseMethod(p);
    int Mod = store.F * 2 + store.S * 2;
    s = s % Mod;

    P A, B;
    if (0 < s && s < store.F) {

      A = P(s, store.S);           // left
      B = P(store.F - s, store.S); // right

    } else if (store.F < s && s < store.F + store.S) {

      A = P(store.F, s - store.F);             // top
      B = P(store.F, (store.F + store.S) - s); // bottom

    } else if (store.F + store.S < s && s < store.F * 2 + store.S) {

      A = P(s - (store.F + store.S), store.S);
      B = P((store.F * 2 + store.S) - s, store.S);

    } else if (store.F * 2 + store.S < s && s < store.F * 2 + store.S * 2) {

      A = P(store.F, s - (store.F * 2 + store.S));
      B = P(store.F, (store.F * 2 + store.S * 2) - s);

    } else
      assert(false);

    if (A.F * A.S < B.F * B.S)
      info.pb(A), info.pb(B);
    else
      info.pb(B), info.pb(A);
  }

  void eraseMethod(int p) {
    vector<P>::iterator it = info.begin();
    for (int cnt = 0; cnt != p; it++, cnt++)
      if (cnt > info.size())
        assert(false);
    info.erase(it);
  }

  void sortVector(vector<P> vec) {
    vector<int> area;
    rep(i, vec.size()) area.pb(vec[i].F * vec[i].S);
    sort(all(area));
    printVector(area);
  }

  void printVector(vector<int> vec) {
    rep(i, vec.size()) {
      cout << vec[i];
      if (i != vec.size() - 1)
        cout << ' ';
    }
    cout << endl;
  }

  int getInfoSize() { return info.size(); }
};

int main() {

  while (true) {
    int _n, _w, _d;
    cin >> _n >> _w >> _d;
    // cerr << _n << " " << _w << " " << _d << endl;
    if (_n + _w + _d == 0)
      break;

    Solve ans(_n, _w, _d);

    rep(i, ans.getN()) {
      int p, s;
      cin >> p >> s;
      // cerr << p << " " << s << endl;
      ans.cutInfo(p - 1, s);
    }
    // cerr << endl;

    ans.getAns();
  }

  return 0;
}

Error: 0
3 5 6
1 18
2 19
1 2

3 4 1
1 1
2 1
3 1

0 2 5

0 0 0


Fixed submission:

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define INF 1 << 27
#define all(n) n.begin(), n.end()
#define insert(a, b, c, d) PP(P(a, b), P(c, d))
#define F first
#define S second
#define pb push_back
#define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef long long ll;
typedef unsigned long long ull;

class Solve {
private:
  int n, w, d;
  vector<P> info;

public:
  Solve(int _n, int _w, int _d) : n(_n), w(_w), d(_d) { info.pb(P(w, d)); }
  ~Solve() {}

  int getN() { return n; }

  int getW() { return w; }

  int getD() { return d; }

  void printAll() {
    cout << "n = " << n << ",w = " << w << ",d = " << d << endl;
    cout << "info---" << endl;
    rep(i, info.size()) {
      cout << i << " - th : " << info[i].F << "," << info[i].S << endl;
    }
    cout << "end---" << endl;
  }

  void getAns() {
    rep(i, info.size()) {
      cout << info[i].F * info[i].S;
      if (i != info.size() - 1)
        cout << ' ';
    }
    cout << endl;
  }

  void cutInfo(int p, int s) {
    P store = info[p];
    eraseMethod(p);
    int Mod = store.F * 2 + store.S * 2;
    s = s % Mod;

    P A, B;
    if (0 < s && s < store.F) {

      A = P(s, store.S);           // left
      B = P(store.F - s, store.S); // right

    } else if (store.F < s && s < store.F + store.S) {

      A = P(store.F, s - store.F);             // top
      B = P(store.F, (store.F + store.S) - s); // bottom

    } else if (store.F + store.S < s && s < store.F * 2 + store.S) {

      A = P(s - (store.F + store.S), store.S);
      B = P((store.F * 2 + store.S) - s, store.S);

    } else if (store.F * 2 + store.S < s && s < store.F * 2 + store.S * 2) {

      A = P(store.F, s - (store.F * 2 + store.S));
      B = P(store.F, (store.F * 2 + store.S * 2) - s);

    } else
      assert(false);

    if (A.F * A.S < B.F * B.S)
      info.pb(A), info.pb(B);
    else
      info.pb(B), info.pb(A);
  }

  void eraseMethod(int p) {
    vector<P>::iterator it = info.begin();
    for (int cnt = 0; cnt != p; it++, cnt++)
      if (cnt > info.size())
        assert(false);
    info.erase(it);
  }

  void sortInfo() { sort(all(info)); }
};

int main() {

  while (true) {
    int _n, _w, _d;
    cin >> _n >> _w >> _d;
    cerr << _n << " " << _w << " " << _d << endl;
    if (_n + _w + _d == 0)
      break;

    Solve ans(_n, _w, _d);

    rep(i, ans.getN()) {
      int p, s;
      cin >> p >> s;
      cerr << p << " " << s << endl;
      ans.cutInfo(p - 1, s);
    }
    cerr << endl;
    ans.sortInfo();

    ans.getAns();
  }

  return 0;
}