fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "icebear"
  33. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */
  34.  
  35. const int MOD = 1e9 + 7;
  36. const int inf = 1e9 + 27092008;
  37. const ll INF = 1e18 + 27092008;
  38. const int N = 500 + 5;
  39. const int CIRCLE = 60;
  40. const int dx[] = {1, -1, 0, 0};
  41. const int dy[] = {0, 0, 1, -1};
  42. int numType, limBoard, numObs;
  43. ii src, dest;
  44. struct Obstacle {
  45. int x, y, r, t;
  46. } obs[N];
  47.  
  48. bool board[CIRCLE + 5][N][N];
  49. int dist[CIRCLE + 5][N][N];
  50.  
  51. void init(void) {
  52. cin >> numType >> limBoard >> numObs;
  53. FOR(i, 1, numObs) cin >> obs[i].x >> obs[i].y >> obs[i].r >> obs[i].t;
  54. cin >> src.fi >> src.se >> dest.fi >> dest.se;
  55. }
  56.  
  57. void process(void) {
  58. FOR(s, 0, CIRCLE) {
  59. FOR(i, 1, numObs) {
  60. int radius = (obs[i].t + s) % obs[i].r;
  61. FOR(j, -radius, radius) FOR(k, -radius, radius)
  62. if (abs(j) + abs(k) <= radius && obs[i].x + j > 0 && obs[i].x + j <= limBoard && obs[i].y + k > 0 && obs[i].y + k <= limBoard)
  63. board[s][obs[i].x + j][obs[i].y + k] = true;
  64. }
  65. }
  66.  
  67. if (numType == 1) {
  68. int ans = 0;
  69. FOR(s, 0, CIRCLE) {
  70. int cnt = 0;
  71. FOR(i, 1, limBoard) FOR(j, 1, limBoard) cnt += board[s][i][j];
  72. maximize(ans, cnt);
  73. }
  74. cout << ans;
  75. } else {
  76. struct stateCell {
  77. int x, y, s, dist;
  78. stateCell(int _x = 0, int _y = 0, int _s = 0, int _d = 0):
  79. x(_x), y(_y), s(_s), dist(_d) {}
  80. bool operator < (const stateCell &other) const {
  81. return dist > other.dist;
  82. }
  83. };
  84. memset(dist, 0x3f, sizeof dist);
  85. priority_queue<stateCell> Q;
  86. dist[0][src.fi][src.se] = 0;
  87. Q.push(stateCell(src.fi, src.se, 0, 0));
  88. while(!Q.empty()) {
  89. auto T = Q.top(); Q.pop();
  90. if (T.dist != dist[T.s][T.x][T.y]) continue;
  91. if (T.x == dest.fi && T.y == dest.se) {
  92. cout << T.dist;
  93. exit(0);
  94. }
  95. if (board[(T.s + 1) % CIRCLE][T.x][T.y] == false && minimize(dist[(T.s + 1) % CIRCLE][T.x][T.y], T.dist + 1))
  96. Q.push(stateCell((T.s + 1) % CIRCLE, T.x, T.y, T.dist + 1));
  97. REP(d, 4) {
  98. int u = T.x + dx[d];
  99. int v = T.y + dy[d];
  100. if (u < 1 || u > limBoard || v < 1 || v > limBoard || board[(T.s + 1) % CIRCLE][u][v]) continue;
  101. if (minimize(dist[(T.s + 1) % CIRCLE][u][v], T.dist + 1))
  102. Q.push(stateCell(u, v, (T.s + 1) % CIRCLE, T.dist + 1));
  103. }
  104. }
  105. }
  106. }
  107.  
  108. int main() {
  109. ios_base::sync_with_stdio(0);
  110. cin.tie(0); cout.tie(0);
  111. if (fopen(task".inp", "r")) {
  112. freopen(task".inp", "r", stdin);
  113. freopen(task".out", "w", stdout);
  114. }
  115. int tc = 1;
  116. // cin >> tc;
  117. while(tc--) {
  118. init();
  119. process();
  120. }
  121. return 0;
  122. }
  123.  
Success #stdin #stdout 0.02s 128988KB
stdin
Standard input is empty
stdout
Standard output is empty