fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int T = 100;
  5. const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
  6. const int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
  7.  
  8. int level, k;
  9. vector<pair<int, int>> live;
  10. int sz, tag1[301][301], tag2[301][301];
  11.  
  12. void msg(string s) {
  13. cout << s << '\n';
  14. exit(0);
  15. }
  16.  
  17. int main() {
  18. cin >> level;
  19. if (level < 1 || level > 3) msg("level must >= 1 and <= 3");
  20. if (level == 1) live = {{20, 20}, {20, 21}, {21, 20}, {21, 21}};
  21. if (level == 2) live = {{20, 20}, {20, 21}, {21, 20}, {21, 21}, {23, 23}, {23, 24}, {24, 23}, {24, 24}};
  22. if (level == 3) live = {{20, 20}, {20, 21}, {21, 20}, {22, 22}, {23, 21}, {23, 22}};
  23.  
  24. cin >> k;
  25. if (k < 0 || k > 100) msg("k must >= 0 and <= 100");
  26. set<pair<int, int>> s;
  27. for (int i = 1; i <= k; i++) {
  28. int x, y;
  29. cin >> x >> y;
  30. if (x < 0 || x > 9 || y < 0 || y > 9) msg("x, y must >= 0 and <= 9");
  31. if (s.count({x, y})) msg("repeated x, y");
  32. s.emplace(x, y);
  33. live.emplace_back(x, y);
  34. }
  35.  
  36. for (int t = 1; t <= T && live.size(); t++) {
  37. vector<pair<int, int>> cand, nxt;
  38. sz++;
  39. for (auto [x, y] : live) {
  40. tag1[x + 100][y + 100] = tag2[x + 100][y + 100] = sz;
  41. cand.emplace_back(x, y);
  42. }
  43. for (auto [x, y] : live) for (int i = 0; i < 8; i++) if (tag2[x + dx[i] + 100][y + dy[i] + 100] != sz) {
  44. cand.emplace_back(x + dx[i], y + dy[i]);
  45. tag2[x + dx[i] + 100][y + dy[i] + 100] = sz;
  46. }
  47. for (auto [x, y] : cand) {
  48. int cnt = 0;
  49. for (int i = 0; i < 8 && cnt <= 3; i++) cnt += (tag1[x + dx[i] + 100][y + dy[i] + 100] == sz);
  50. if (tag1[x + 100][y + 100] == sz) {
  51. if (cnt == 2 || cnt == 3) nxt.emplace_back(x, y);
  52. } else {
  53. if (cnt == 3) nxt.emplace_back(x, y);
  54. }
  55. }
  56. live = nxt;
  57. }
  58.  
  59. if (live.size() == 0) msg("accepted");
  60. else msg("wrong answer");
  61. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
level must >= 1 and <= 3