Submission #33763


Source Code Expand

Copy
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

const int dy[4] = {1, 0, -1, 0};
const int dx[4] = {0, 1, 0, -1};

int H, W;
bool fld[2010][2010];

char buf[2010];
bool vis[2010][2010];

int zid[2010][2010];

int main() {
  while (2 == scanf("%d%d", &H, &W)) {
    rep (y, H) {
      scanf("%s", buf);
      rep (x, W) fld[y][x] = buf[x] == 'o';
    }

    int cnt[10] = {};

    memset(vis, 0, sizeof(vis));
    int Z = 0;
    rep (sy, H) rep (sx, W) if (!fld[sy][sx] && !vis[sy][sx]) {
      queue<pair<int, int> > que;
      que.push(mp(sx, sy));

      while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();

        zid[y][x] = Z;

        rep (d, 4) {
          int tx = x + dx[d];
          int ty = y + dy[d];
          if (tx < 0 || ty < 0 || W <= tx || H <= ty) continue;
          if (fld[ty][tx] || vis[ty][tx]) continue;
          que.push(mp(tx, ty));
          vis[ty][tx] = true;
        }
      }

      ++Z;
    }

    rep (sy, H) rep (sx, W) if (fld[sy][sx] && !vis[sy][sx]) {
      queue<pair<int, int> > que;
      que.push(mp(sx, sy));
      vis[sy][sx] = true;
      vector<int> zs;

      while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();

        for (int dx = -1; dx <= 1; ++dx) {
          for (int dy = -1; dy <= 1; ++dy) {
            int tx = x + dx;
            int ty = y + dy;
            if (!fld[ty][tx]) {
              zs.pb(zid[ty][tx]);
            } else {
              if (vis[ty][tx]) continue;
              que.push(mp(tx, ty));
              vis[ty][tx] = true;
            }
          }
        }
      }

      sort(all(zs));
      int c = unique(all(zs)) - zs.begin();
      ++cnt[c - 1];
    }

    printf("%d %d %d\n", cnt[1], cnt[2], cnt[0]);
  }

  return 0;
}

Submission Info

Submission Time
Task D - アルファベット探し
User iwiwi
Language C++ (G++ 4.6.4)
Score 100
Code Size 2500 Byte
Status AC
Exec Time 172 ms
Memory 14592 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:40:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 58
Set Name Test Cases
All 00_min.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 00_sample_04.txt, 00_sample_05.txt, 01_rndsmall_00.txt, 01_rndsmall_01.txt, 01_rndsmall_02.txt, 01_rndsmall_03.txt, 01_rndsmall_04.txt, 01_rndsmall_05.txt, 01_rndsmall_06.txt, 01_rndsmall_07.txt, 01_rndsmall_08.txt, 01_rndsmall_09.txt, 01_rndsmall_10.txt, 01_rndsmall_11.txt, 01_rndsmall_12.txt, 01_rndsmall_13.txt, 01_rndsmall_14.txt, 01_rndsmall_15.txt, 01_rndsmall_16.txt, 01_rndsmall_17.txt, 01_rndsmall_18.txt, 01_rndsmall_19.txt, 02_rndmax_00.txt, 02_rndmax_01.txt, 02_rndmax_02.txt, 02_rndmax_03.txt, 02_rndmax_04.txt, 02_rndmax_05.txt, 02_rndmax_06.txt, 02_rndmax_07.txt, 02_rndmax_08.txt, 02_rndmax_09.txt, 02_rndmax_10.txt, 02_rndmax_11.txt, 02_rndmax_12.txt, 02_rndmax_13.txt, 02_rndmax_14.txt, 02_rndmax_15.txt, 02_rndmax_16.txt, 02_rndmax_17.txt, 02_rndmax_18.txt, 02_rndmax_19.txt, 03_rnd_00.txt, 03_rnd_01.txt, 03_rnd_02.txt, 03_rnd_03.txt, 03_rnd_04.txt, 03_rnd_05.txt, 03_rnd_06.txt, 03_rnd_07.txt, 03_rnd_08.txt, 03_rnd_09.txt, 04_empty_00.txt, 05_maxret_00.txt
Case Name Status Exec Time Memory
00_min.txt AC 28 ms 4756 KB
00_sample_01.txt AC 29 ms 4756 KB
00_sample_02.txt AC 28 ms 4756 KB
00_sample_03.txt AC 28 ms 4724 KB
00_sample_04.txt AC 29 ms 4748 KB
00_sample_05.txt AC 29 ms 4984 KB
01_rndsmall_00.txt AC 29 ms 5376 KB
01_rndsmall_01.txt AC 29 ms 5372 KB
01_rndsmall_02.txt AC 30 ms 5372 KB
01_rndsmall_03.txt AC 30 ms 5372 KB
01_rndsmall_04.txt AC 28 ms 5376 KB
01_rndsmall_05.txt AC 30 ms 5388 KB
01_rndsmall_06.txt AC 29 ms 5372 KB
01_rndsmall_07.txt AC 28 ms 5372 KB
01_rndsmall_08.txt AC 29 ms 5396 KB
01_rndsmall_09.txt AC 30 ms 5380 KB
01_rndsmall_10.txt AC 30 ms 5320 KB
01_rndsmall_11.txt AC 28 ms 5364 KB
01_rndsmall_12.txt AC 28 ms 5368 KB
01_rndsmall_13.txt AC 29 ms 5364 KB
01_rndsmall_14.txt AC 29 ms 5368 KB
01_rndsmall_15.txt AC 27 ms 5400 KB
01_rndsmall_16.txt AC 27 ms 5392 KB
01_rndsmall_17.txt AC 28 ms 5372 KB
01_rndsmall_18.txt AC 29 ms 5328 KB
01_rndsmall_19.txt AC 29 ms 5372 KB
02_rndmax_00.txt AC 103 ms 14584 KB
02_rndmax_01.txt AC 122 ms 14580 KB
02_rndmax_02.txt AC 146 ms 14456 KB
02_rndmax_03.txt AC 116 ms 14592 KB
02_rndmax_04.txt AC 130 ms 14460 KB
02_rndmax_05.txt AC 108 ms 14580 KB
02_rndmax_06.txt AC 89 ms 14568 KB
02_rndmax_07.txt AC 95 ms 14592 KB
02_rndmax_08.txt AC 109 ms 14592 KB
02_rndmax_09.txt AC 100 ms 14580 KB
02_rndmax_10.txt AC 104 ms 14588 KB
02_rndmax_11.txt AC 104 ms 14588 KB
02_rndmax_12.txt AC 109 ms 14592 KB
02_rndmax_13.txt AC 101 ms 14584 KB
02_rndmax_14.txt AC 93 ms 14584 KB
02_rndmax_15.txt AC 124 ms 14588 KB
02_rndmax_16.txt AC 113 ms 14580 KB
02_rndmax_17.txt AC 96 ms 14584 KB
02_rndmax_18.txt AC 104 ms 14584 KB
02_rndmax_19.txt AC 110 ms 14464 KB
03_rnd_00.txt AC 29 ms 4984 KB
03_rnd_01.txt AC 47 ms 9984 KB
03_rnd_02.txt AC 51 ms 7036 KB
03_rnd_03.txt AC 48 ms 8704 KB
03_rnd_04.txt AC 48 ms 7672 KB
03_rnd_05.txt AC 34 ms 5500 KB
03_rnd_06.txt AC 70 ms 9720 KB
03_rnd_07.txt AC 37 ms 6524 KB
03_rnd_08.txt AC 67 ms 12672 KB
03_rnd_09.txt AC 68 ms 9848 KB
04_empty_00.txt AC 87 ms 14464 KB
05_maxret_00.txt AC 172 ms 14468 KB