Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
  3. #pragma GCC option("arch=native","tune=native","no-zero-upper")
  4. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  5. using namespace std;
  6. unsigned char bits[15800000];
  7. bool get_used (int ch) {
  8. int numb=14*ch;
  9. return bits[numb/8]&(1<<(numb%8));
  10. }
  11. int get_dist (int ch) {
  12. int ans=0;
  13. for (int numb=1;numb<=13;numb++) {
  14. ans+=(1<<(numb-1))*bool(bits[(ch*14+numb)/8]&(1<<((ch*14+numb)%8)));
  15. }
  16. return ans;
  17. }
  18. void set_used(int ch) {
  19. int numb=14*ch;
  20. bits[numb/8]|=(1<<numb%8);
  21. }
  22. void set_dist(int ch, int zn) {
  23.  
  24. for (int numb=1;numb<=13;numb++) {
  25. if (zn&(1<<(numb-1))) bits[(ch*14+numb)/8]|=(1<<((ch*14+numb)%8));
  26. }
  27. }
  28. int main() {
  29. int a,b;
  30. cin>>a>>b;
  31. int k;
  32. cin>>k;
  33. queue <pair<short int, short int>> q;
  34. for (int i=0;i<k;i++) {
  35. int x,y; cin>>x>>y; x--; y--; set_used(3001*x+y);
  36. q.push({x,y});
  37. }
  38. short int max1=0;
  39.  
  40. while (!q.empty()) {
  41. pair <short int, short int> c=q.front();
  42. q.pop();
  43. short int kek=get_dist(c.first*3001+c.second);
  44. max1=max(max1,kek);
  45. if (c.first>0 && get_used(c.first*3001+c.second-3001)==false) {
  46. set_used(c.first*3001+c.second-3001); set_dist(c.first*3001+c.second-3001,kek+1);
  47. q.push({c.first-1,c.second});
  48. }
  49. if (c.second>0 && get_used(c.first*3001+c.second-1)==false) {
  50. set_used(c.first*3001+c.second-1); set_dist(c.first*3001+c.second-1,kek+1);
  51. q.push({c.first,c.second-1});
  52. }
  53. if (c.first<a-1 && get_used(c.first*3001+c.second+3001)==false) {
  54. set_used(c.first*3001+c.second+3001); set_dist(c.first*3001+c.second+3001,kek+1);
  55. q.push({c.first+1,c.second});
  56. }
  57. if (c.second<b-1 && get_used(c.first*3001+c.second+1)==false) {
  58. set_used(c.first*3001+c.second+1); set_dist(c.first*3001+c.second+1,kek+1);
  59. q.push({c.first,c.second+1});
  60. }
  61. }
  62. cout<<max1;
  63.  
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement