Submission #2022782


Source Code Expand

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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))


class UnionFind {
  vector<int> data;
 public:
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};


int R, C;
vector<string> m;

inline int RC(int r, int c) {
    return r*C + c;
}

int solve() {
    UnionFind uf(R*C);

    rep(r, R) rep(c, C-1) {
        if (m[r][c] == '.' && m[r][c+1] == '.') uf.unionSet(RC(r,c), RC(r,c+1));
    }
    rep(r, R-1) rep(c, C) {
        if (m[r][c] == '.' && m[r+1][c] == '.') uf.unionSet(RC(r,c), RC(r+1,c));
    }

#if 0
    rep(r, R){
        rep(c, C) {
            if (m[r][c] == '.') {
                int rt = uf.root(RC(r,c));
                printf(" %2d", rt);
            } else {
                printf("  .");
            }
        }
        printf("\n");
    }
#endif

    set<int> s;
    rep(r, R) rep(c, C) {
        if (m[r][c] == '.') {
            s.insert(uf.root(RC(r,c)));
        }
    }

    int total = 0;

    for (int rt : s) {
        vector<int> cnt(2, 0);
        rep(r, R) rep(c, C) {
            int b = (r ^ c) % 2;
            if (m[r][c] == '.' && uf.root(RC(r,c)) == rt) {
                ++cnt[b];
            }
        }
        total += max(cnt[0], cnt[1]);
    }

    return total;
}

int main() {
    cin >> R >> C;

    m.resize(R);
    rep(r, R) cin >> m[r];

    cout << solve() << endl;

    return 0;
}

Submission Info

Submission Time
Task C - 広告
User naoya_t
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2800 Byte
Status WA
Exec Time 2 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 9
WA × 12
Set Name Test Cases
Sample sample0.txt, sample1.txt, sample2.txt, sample3.txt
All 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, sample0.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
01-00.txt AC 1 ms 256 KB
01-01.txt WA 2 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt WA 2 ms 256 KB
01-04.txt WA 1 ms 256 KB
01-05.txt WA 2 ms 256 KB
01-06.txt WA 2 ms 256 KB
01-07.txt AC 1 ms 256 KB
01-08.txt WA 2 ms 256 KB
01-09.txt WA 1 ms 256 KB
01-10.txt WA 2 ms 256 KB
01-11.txt AC 1 ms 256 KB
01-12.txt WA 1 ms 256 KB
01-13.txt WA 1 ms 256 KB
01-14.txt WA 2 ms 256 KB
01-15.txt WA 1 ms 256 KB
01-16.txt AC 1 ms 256 KB
sample0.txt AC 1 ms 256 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB