Facebook
From jesan, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 128
  1. #include<bits/stdc++.h>
  2. #include <deque>
  3. using namespace std;
  4. #define faster ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
  5. #define ff  first
  6. #define ss  second
  7. #define ll  long long int
  8. #define File  freopen("input.txt","r", stdin);freopen("output.txt","w", stdout);
  9. #define testCase int tc = 1; cin >> tc;for(int i = 1;i<=tc;i++)
  10. #define INF 0x7F
  11. #define MIN_INF 0x80
  12. #define pii acos(-1.0)
  13. const int mx = 1e5 + 111;
  14. int dir_x[] = {-1,-1,-1,0,1,1,1,0};
  15. int dir_y[] = {-1,0,1,1,1,0,-1,-1};
  16. ll lastonebits(int n)
  17. {
  18.   return n&(-n);
  19. }
  20. template<typename T>
  21.  
  22. void input(vector < T> &arr)
  23. {
  24.     ll a;
  25.     cin >> a;
  26.     arr.push_back(a);
  27.    
  28. }
  29.  
  30. void solve()
  31. {
  32.   ll n,m,k;
  33.   cin >> n >> m >> k;
  34.   ll total = ((m-2ll)*4ll) + 3ll + 2ll;
  35.   total = (n-1) * total;
  36.   total = total + m-1;
  37.  // cout << total << endl;
  38.   map< pair < ll,ll >,int>blk;
  39.   map < array<ll, 4>,ll> taken;
  40.   for(int i = 0;i<k;i++)
  41.   {
  42.     ll a,b;
  43.     cin >> a >> b;
  44.     blk[{a,b}] = 1;
  45.    
  46.     //cout << a<< " " << b << endl;
  47.   }
  48.   if(n == 1 && m == 1 && k > 0)
  49.   {
  50.     cout << 0 << endl;
  51.     return;
  52.   }
  53.   if(n == 1 && m == 2 && k > 0)
  54.   {
  55.     cout << 0 << endl;
  56.     return;
  57.   }
  58.   if(n == 2 && m == 1 && k > 0)
  59.   {
  60.     cout << 0 << endl;
  61.     return;
  62.   }
  63.   ll sum = 0;
  64.  
  65.   for(auto i:blk)
  66.   {
  67.     ll count = 0;
  68.     pair < int,int > node  = i.ff;
  69.    
  70.    // cout << 's' << endl;
  71.    
  72.     for(int j = 0;j<8;j++)
  73.     {
  74.       int x = node.ff + dir_x[j];
  75.       int y = node.ss + dir_y[j];
  76.       array<ll, 4>v,b;
  77.       v= {node.ff,node.ss,x,y};
  78.       b= {x,y,node.ff,node.ss};
  79.       if(x >= 1 && x <= n && y >= 1 && y<=m && (taken[v] == 0 || taken[b] == 0))
  80.       {
  81.         count++;
  82.         taken[v] = 1;
  83.         taken[b] = 1;
  84.       }
  85.     }
  86.    // cout << count << endl;
  87.    sum += count;
  88.   }
  89.   //sum++;
  90.   cout << total - sum << endl;
  91. }
  92.  
  93. int main()
  94. {
  95.    faster;
  96.    #ifndef ONLINE_JUDGE
  97.    File
  98.    #endif
  99.    testCase
  100.       {
  101.        // cout << "Case #" << i << ": ";
  102.         solve();
  103.       }
  104.  
  105. }