Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
- #pragma GCC option("arch=native","tune=native","no-zero-upper")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
- using namespace std;
- unsigned char bits[15800000];
- bool get_used (int ch) {
- int numb=14*ch;
- return bits[numb/8]&(1<<(numb%8));
- }
- int get_dist (int ch) {
- int ans=0;
- for (int numb=1;numb<=13;numb++) {
- ans+=(1<<(numb-1))*bool(bits[(ch*14+numb)/8]&(1<<((ch*14+numb)%8)));
- }
- return ans;
- }
- void set_used(int ch) {
- int numb=14*ch;
- bits[numb/8]|=(1<<numb%8);
- }
- void set_dist(int ch, int zn) {
- for (int numb=1;numb<=13;numb++) {
- if (zn&(1<<(numb-1))) bits[(ch*14+numb)/8]|=(1<<((ch*14+numb)%8));
- }
- }
- int main() {
- int a,b;
- cin>>a>>b;
- int k;
- cin>>k;
- queue <pair<short int, short int>> q;
- for (int i=0;i<k;i++) {
- int x,y; cin>>x>>y; x--; y--; set_used(3001*x+y);
- q.push({x,y});
- }
- short int max1=0;
- while (!q.empty()) {
- pair <short int, short int> c=q.front();
- q.pop();
- short int kek=get_dist(c.first*3001+c.second);
- max1=max(max1,kek);
- if (c.first>0 && get_used(c.first*3001+c.second-3001)==false) {
- set_used(c.first*3001+c.second-3001); set_dist(c.first*3001+c.second-3001,kek+1);
- q.push({c.first-1,c.second});
- }
- if (c.second>0 && get_used(c.first*3001+c.second-1)==false) {
- set_used(c.first*3001+c.second-1); set_dist(c.first*3001+c.second-1,kek+1);
- q.push({c.first,c.second-1});
- }
- if (c.first<a-1 && get_used(c.first*3001+c.second+3001)==false) {
- set_used(c.first*3001+c.second+3001); set_dist(c.first*3001+c.second+3001,kek+1);
- q.push({c.first+1,c.second});
- }
- if (c.second<b-1 && get_used(c.first*3001+c.second+1)==false) {
- set_used(c.first*3001+c.second+1); set_dist(c.first*3001+c.second+1,kek+1);
- q.push({c.first,c.second+1});
- }
- }
- cout<<max1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement