0.5に注意する。
class AntsMeet { public: int countAnts(vector <int> X, vector <int> Y, string D) { for (int i = 0; i < (int)D.size(); ++i) { X[i] *= 2; Y[i] *= 2; } for (int loop = 4005; loop--; ) { for (int i = 0; i < (int)D.size(); ++i) { if (D[i] == 'N') ++Y[i]; if (D[i] == 'E') ++X[i]; if (D[i] == 'S') --Y[i]; if (D[i] == 'W') --X[i]; } map< pair<int, int>, int > cnt; for (int i = 0; i < (int)D.size(); ++i) { ++cnt[make_pair(X[i], Y[i])]; } for (int i = 0; i < (int)D.size(); ++i) { pair<int, int> p = make_pair(X[i], Y[i]); if (1 < cnt[p]) { X.erase(X.begin() + i); Y.erase(Y.begin() + i); D.erase(D.begin() + i); --i; } } } return D.size(); } };