Advertisement
a53

pulsar

a53
May 19th, 2022
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin("pulsar.in");
  6. ofstream fout("pulsar.out");
  7.  
  8. int dx[] = {-1, 1, 0 ,0, 0};
  9. int dy[] = {0, 0, -1, 1, 0};
  10.  
  11. int a[65][505][505];
  12. int dist[65][505][505];
  13. bool viz[65][505][505];
  14. long long cer, n, p, xs, ys, xf, yf, cmmmc = 1, r;
  15.  
  16. struct pulsari {
  17. long long x, y, r, t;
  18. }v[15005];
  19.  
  20. struct pulsari1 {
  21. long long x, y, stare;
  22. };
  23.  
  24. int lcm(int a, int b) {
  25. return a * b / __gcd(a, b);
  26. }
  27.  
  28. int manhattandist(int xc, int yc, int xstart, int ystart) {
  29. return abs(xc - xstart) + abs(yc - ystart);
  30. }
  31.  
  32. bool verif(int a, int b) {
  33. return a >= 1 && a <= n && b >= 1 && b <= n;
  34. }
  35.  
  36. void fillM(int xc, int yc, int raza, int stare, int xstart, int ystart) {
  37. a[stare][xc][yc] = 1;
  38. if(manhattandist(xc, yc, xstart, ystart) == r) {
  39. return;
  40. }
  41. for(int k = 0; k <= 4; k++) {
  42. int xNou = xc + dx[k];
  43. int yNou = yc + dy[k];
  44. if(verif(xNou, yNou) && manhattandist(xc, yc, xstart, ystart) < manhattandist(xstart, ystart, xNou, yNou)) {
  45. fillM(xNou, yNou, raza, stare, xstart, ystart);
  46. }
  47. }
  48. }
  49.  
  50. int main() {
  51. fin >> cer >> n >> p;
  52. for(int i = 1; i <= p; i++) {
  53. fin >> v[i].x >> v[i].y >> v[i].r >> v[i].t;
  54. cmmmc = lcm(cmmmc, v[i].r);
  55. }
  56. fin >> xs >> ys >> xf >> yf;
  57. for(int i = 0; i <= cmmmc-1; i++) {
  58. for(int j = 1; j <= p; j++) {
  59. r = (i + v[j].t) % v[j].r;
  60. fillM(v[j].x, v[j].y, r, i, v[j].x, v[j].y);
  61. }
  62. }
  63. if(cer == 1) {
  64. int mx = INT_MIN;
  65. for(int i = 0; i < cmmmc; i++) {
  66. int nr = 0;
  67. for(int j = 1; j <= n; j++) {
  68. for(int k = 1; k <= n; k++) {
  69. if(a[i][j][k] == 1) {
  70. nr++;
  71. }
  72. }
  73. }
  74. mx = max(nr, mx);
  75. }
  76. fout << mx;
  77. }
  78. if(cer == 2) {
  79. for(int i=0; i<60; i++) {
  80. for (int j = 1; j <= n; j++) {
  81. for (int k = 1; k <= n; k++) {
  82. dist[i][j][k] = 1e9;
  83. }
  84. }
  85. }
  86. queue<pulsari1> q;
  87. q.push({xs, ys, 0});
  88. dist[0][xs][ys] = 1;
  89. viz[0][xs][ys] = true;
  90. while(!q.empty()) {
  91. pulsari1 now = q.front();
  92. q.pop();
  93. for(int k = 0; k <= 4; k++) {
  94. pulsari1 nxt;
  95. nxt.x = now.x + dx[k];
  96. nxt.y = now.y + dy[k];
  97. nxt.stare = (now.stare + 1) % cmmmc;
  98. if(verif(nxt.x, nxt.y) && a[nxt.stare][nxt.x][nxt.y] != 1 && !viz[nxt.stare][nxt.x][nxt.y]) {
  99. q.emplace(nxt);
  100. dist[nxt.stare][nxt.x][nxt.y] = dist[now.stare][now.x][now.y] + 1;
  101. viz[nxt.stare][nxt.x][nxt.y] = true;
  102. }
  103. }
  104. }
  105. int mn = 1e9;
  106. for(int i = 0; i < cmmmc; i++) {
  107. mn = min(mn, dist[i][xf][yf]);
  108. }
  109. fout << mn-1;
  110. }
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement