QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#348397#7733. Cool, It’s Yesterday Four Times MoreLainRE 0ms3592kbC++232.3kb2024-03-09 18:13:322024-03-09 18:13:32

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 18:13:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3592kb
  • [2024-03-09 18:13:32]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);


  int tt;
  cin >> tt;
  while(tt--) {
    int n, m;
    cin >> n >> m;

    struct node {
      int p, s;
    };
    vector<node> nodes(n*m);
    rep(i, 0, n*m) {
      nodes[i].p = i;
      nodes[i].s = 1;
    }
    auto find = [&](auto& self, int s)->int {
      if (s == nodes[s].p) return s;
      return nodes[s].p = self(self, nodes[s].p);
    };
    auto merge = [&](int a, int b)->bool {
      a = find(find, a);
      b = find(find, b);
      if ( a== b) return false;
      if (nodes[a].s < nodes[b].s) swap(a, b);
      nodes[b].p = a;
      nodes[a].s += nodes[b].s;
      return true;
    };

    vector<string> v(n);
    for (auto& x : v) cin >> x;

    vi dxs = {-1, 1, 0, 0};
    vi dys = {0, 0, -1, 1};
    rep(i, 0, n) {
      rep(j, 0, m) {
        if (v[i][j] == '.') {
          rep(k, 0, 4) {
            int ni = i + dxs[k];
            int nj = j + dys[k];
            if (ni < 0 || ni >= n || nj < 0 || nj >= m || v[ni][nj] == 'O')  continue;
            merge(m*i + j, m * ni + nj);
          }
        }
      }
    }

    // collect values.
    vector<vector<pii>> groups(n*m);
    rep(i, 0, n) {
      rep(j, 0, m) {
        if (v[i][j] == '.') {
          groups[find(find, m*i + j)].push_back({i, j});
        }
      }
    }
    using bs = bitset<5000>;
    vector<bs> sets;
    auto encode = [&](int x, int y)->int {
      return (m - 1 + x) * (2 * n - 1) + (n - 1 + y);
    };
    for (auto& g : groups) {
      if (sz(g) == 0) continue;
      rep(i, 0, sz(g)) {
        bs b;
        rep(j, 0, sz(g)) {
          int x = g[i].first - g[j].first;
          int y = g[i].second - g[j].second;
          b.set(encode(x, y));
        }
        sets.push_back(b);
      }
    }
    int ans = 0;
    rep(i, 0, sz(sets)) {
      bool ok = true;
      rep(j, 0, sz(sets)) {
        if (i == j) continue;
        if ((sets[i] & sets[j]) == sets[i]) {
          ok = false;
          break;
        }
      }
      ans += ok;
    }
    cout << ans << '\n';
  }
}


詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3592kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

3
1
0
0

result:

ok 4 lines

Test #2:

score: -100
Runtime Error

input:

200
2 4
OOO.
OO..
2 3
OOO
.O.
3 3
O.O
OOO
OO.
4 1
.
.
O
O
1 2
.O
1 1
.
2 5
.OO..
.O.O.
2 1
O
O
1 1
O
1 3
.OO
5 1
O
O
.
O
.
5 2
O.
..
O.
.O
..
5 3
...
...
.OO
..O
OOO
3 5
..O.O
.O.O.
.OO.O
5 2
.O
OO
O.
O.
..
2 1
O
O
3 5
.O.OO
O...O
..OO.
1 5
.....
5 1
O
.
O
.
.
5 3
OOO
OO.
.OO
OO.
O.O
2 1
O
.
5 2
O.
...

output:


result: