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[15005];
  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. FOR(i, 1, limBoard) FOR(j, 1, limBoard) assert(board[0][i][j] == board[CIRCLE][i][j]);
  68.  
  69. if (numType == 1) {
  70. int ans = 0;
  71. FOR(s, 0, CIRCLE) {
  72. int cnt = 0;
  73. FOR(i, 1, limBoard) FOR(j, 1, limBoard) cnt += board[s][i][j];
  74. maximize(ans, cnt);
  75. }
  76. cout << ans;
  77. } else {
  78. struct stateCell {
  79. int x, y, s;
  80. stateCell(int _x = 0, int _y = 0, int _s = 0):
  81. x(_x), y(_y), s(_s) {}
  82. };
  83. memset(dist, 0x3f, sizeof dist);
  84. queue<stateCell> Q;
  85. dist[0][src.fi][src.se] = 0;
  86. Q.push(stateCell(src.fi, src.se, 0));
  87. while(!Q.empty()) {
  88. auto T = Q.front(); Q.pop();
  89. if (T.x == dest.fi && T.y == dest.se) {
  90. cout << dist[T.s][T.x][T.y];
  91. exit(0);
  92. }
  93. if (board[(T.s + 1) % CIRCLE][T.x][T.y] == false && minimize(dist[(T.s + 1) % CIRCLE][T.x][T.y], dist[T.s][T.x][T.y] + 1))
  94. Q.push(stateCell(T.x, T.y, (T.s + 1) % CIRCLE));
  95. REP(d, 4) {
  96. int u = T.x + dx[d];
  97. int v = T.y + dy[d];
  98. if (u < 1 || u > limBoard || v < 1 || v > limBoard || board[(T.s + 1) % CIRCLE][u][v]) continue;
  99. if (minimize(dist[(T.s + 1) % CIRCLE][u][v], dist[T.s][T.x][T.y] + 1))
  100. Q.push(stateCell(u, v, (T.s + 1) % CIRCLE));
  101. }
  102. }
  103. }
  104. }
  105.  
  106. int main() {
  107. ios_base::sync_with_stdio(0);
  108. cin.tie(0); cout.tie(0);
  109. if (fopen(task".inp", "r")) {
  110. freopen(task".inp", "r", stdin);
  111. freopen(task".out", "w", stdout);
  112. }
  113. int tc = 1;
  114. // cin >> tc;
  115. while(tc--) {
  116. init();
  117. process();
  118. }
  119. return 0;
  120. }
  121.  
Success #stdin #stdout 0.02s 69416KB
stdin
Standard input is empty
stdout
Standard output is empty