Submission #1187150


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define fir first
#define sec second

struct node {
  int fir;
  int sec;

  node(int fir=0, int sec=0):
    fir(fir), sec(sec) {}

  node(pair<int,int> p):
    fir(p.first), sec(p.second) {}

    bool operator==(const node& a) const {
      return fir==a.fir && sec==a.sec;
    }
};

struct MyHash {
  size_t operator()(const node& a) const {
        return 1LL*a.fir*100005+a.sec;
    }
};

typedef long long LL;
typedef node pii;
pii g[3][3];
pii dir[9][9];
int ID[3][3];
int h, w, n;

inline bool judge(int x, int y) {
  return x<=0 || x>h || y<=0 || y>w;
}

inline bool judge(const pii& p) {
  return p.fir<=0 || p.fir>h || p.sec<=0 || p.sec>w;
}

void init() {
  int c = 0;

  for (int i=0; i<3; ++i) {
    for (int j=0; j<3; ++j) {
      g[i][j].fir = i;
      g[i][j].sec = j;
      ID[i][j] = c++;
    }
  }

  for (int id=0; id<9; ++id) {
    int x = id / 3;
    int y = id % 3;
    int z = 0;
    for (int i=0; i<3; ++i) {
      for (int j=0; j<3; ++j) {
        dir[id][z] = make_pair(g[i][j].fir-x, g[i][j].sec-y);
        ++z;
      }
    }
  }
}

int main() {
  LL c[10];
  pii p;
  init();

  scanf("%d %d %d", &h, &w, &n);
  unordered_set<pii, MyHash> st;
  LL tot = 1LL * (h - 2) * (w - 2);
  for (int i=0; i<n; ++i) {
    scanf("%d %d", &p.fir, &p.sec);
    st.insert(p);
  }
  memset(c, 0, sizeof(c));

  int x, y, xx, yy, cnt;
  bool flag;

  for (auto iter=st.begin(); iter!=st.end(); ++iter) {
    x = iter->fir;
    y = iter->sec;
    for (int id=0; id<9; ++id) {
      flag = true;
      cnt = 0;
      for (int k=0; k<9; ++k) {
        p.fir = x + dir[id][k].fir;
        p.sec = y + dir[id][k].sec;
        if (judge(p)) {
          flag = false;
          break;
        }
        cnt += st.count(p)>0;
      }
      if (flag)
        c[cnt]++;
    }
  }

  c[0] = tot;
  for (int i=1; i<=9; ++i) {
    c[i] /= i;
    c[0] -= c[i];
  }

  for (int i=0; i<10; ++i) {
    cout << c[i] << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task D - Snuke's Coloring
User Trasier
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2101 Byte
Status AC
Exec Time 335 ms
Memory 4388 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:72:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &h, &w, &n);
                                ^
./Main.cpp:76:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &p.fir, &p.sec);
                                   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status AC
AC × 19
Set Name Test Cases
Sample
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, empty.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt AC 295 ms 4388 KB
02.txt AC 325 ms 4388 KB
03.txt AC 78 ms 1280 KB
04.txt AC 1 ms 256 KB
05.txt AC 190 ms 4388 KB
06.txt AC 158 ms 4388 KB
07.txt AC 325 ms 4388 KB
08.txt AC 332 ms 4388 KB
09.txt AC 326 ms 4388 KB
10.txt AC 1 ms 256 KB
11.txt AC 322 ms 4388 KB
12.txt AC 317 ms 4388 KB
13.txt AC 2 ms 256 KB
14.txt AC 330 ms 4388 KB
15.txt AC 335 ms 4388 KB
empty.txt AC 1 ms 256 KB
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB