#1020674

Solution for 0569: Illumination by orisano

Source Code Status Test Cases
    Policy: public     Reviewed: 148    
00.00 sec    1748 KB    82 lines     2282 bytes    2014-07-15 22:24
#include <bits/stdc++.h>

using namespace std;

#define TEMP_T template<typename T>
TEMP_T void sort(T& v){ sort(v.begin(), v.end()); }
TEMP_T void revs(T& v){ reverse(v.begin(), v.end()); }
TEMP_T void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end())); }
TEMP_T void show(T& v, char delim=' ', char end='\n'){ for(int i=0; i<v.size()-1; i++) cout << v[i] << delim; cout << v[v.size()-1] << end; }
TEMP_T T    cums(T& v){ T r; r.push_back(v[0]); for(int i=1; i<v.size(); i++) r.push_back(r[i-1] + v[i]); return r; }
TEMP_T void maxe(T& v, T m){ v = max(v, m); }
TEMP_T void mine(T& v, T m){ v = min(v, m); }

static inline int in(){ int x; scanf("%d", &x); return x; }

struct Solver {
  Solver(){}
  int read_input(){
    w = in();
    h = in();
    memset(field, 0, sizeof(field));
    for (int i = 0; i < h; i++){
      for (int j = 0; j < w; j++){
        field[i + 1][j + 1] = in();
      }
    }
    w += 2;
    h += 2;
    return (0);
  }
  int solve(){
    int sums[128][128] = {};
    queue<pair<int, int> > Q;
    set<pair<int, int> > vis;
    Q.push(make_pair(0, 0));
    vis.insert(make_pair(0, 0));
    while (!Q.empty()){
      queue<pair<int, int> > nQ;
      while (!Q.empty()){
        pair<int, int> p = Q.front();
        Q.pop();
        for (int d = 0; d < 6; d++){
          static const int edx[] = {-1,-1,-1, 0, 1, 0};
          static const int edy[] = {-1, 0, 1,-1, 0, 1};
          static const int odx[] = { 0,-1, 0, 1, 1, 1};
          static const int ody[] = {-1, 0, 1,-1, 0, 1};
          int nx = p.first + ((p.second % 2) ? odx[d] : edx[d]);
          int ny = p.second + ((p.second % 2) ? ody[d] : edy[d]);
          if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
          if (field[ny][nx]){
            sums[ny][nx]++;
            continue;
          }
          if (vis.find(make_pair(nx, ny)) != vis.end()) continue;
          vis.insert(make_pair(nx, ny));
          nQ.push(make_pair(nx, ny));
        }
      }
      swap(Q, nQ);
    }
    int ret = 0;
    for (int i = 0; i < h; i++){
      for (int j = 0; j < w; j++){
        ret += sums[i][j];
      }
    }

    return ret;
  }
  int field[128][128];
  int w, h;
};

int main()
{
  Solver solver;
  solver.read_input();
  printf("%d\n", solver.solve());
  return (0);
}


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 5/5 C++ CPU: 00.00 sec Memory: 1748 KB Length: 2282 B 2014-07-15 22:24 2014-07-15 22:24
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.00 sec 1336 KB
Case #2: : Accepted 00.00 sec 1476 KB
Case #3: : Accepted 00.00 sec 1624 KB
Case #4: : Accepted 00.00 sec 1748 KB
Case #5: : Accepted 00.00 sec 1588 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags