QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#435#243417#7733. Cool, It’s Yesterday Four Times Morewqy2023wqy2023Success!2023-11-08 10:47:142023-11-08 10:47:14

详细

Extra Test:

Wrong Answer
time: 0ms
memory: 3632kb

input:

1
7 2
..
..
OO
O.
..
.O
OO

output:

0

result:

wrong answer 1st lines differ - expected: '8', found: '0'

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#243417#7733. Cool, It’s Yesterday Four Times Morewqy2023WA 21ms3880kbC++202.4kb2023-11-08 10:22:242023-11-08 10:47:43

answer

#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define lowbit(x) ((x) & -(x))
#define SZ(x) (int)x.size()
#ifdef LOCAL
#define cin std::cin
#define cout std::cout
#endif
#ifndef LOCAL
#define endl '\n'
#endif
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }
const int INF = 0x3f3f3f3f,N=1e3+10;
vector<string> s;
int n,m;
vector<bitset<N>> conn;
vector<vector<int>> point;
int d[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int getNum(int a,int b){
    return (a-1)*m+b-1;
}
void dfs(int a,int b){
    s[a][b]='O';
    conn.back()[getNum(a,b)]=1;
    point.back().push_back(getNum(a,b));
    for(int i=0;i<4;i++){
        int da=a+d[i][0],db=b+d[i][1];
        if(s[da][db]!='O') dfs(da,db);
    }
}
int num;
void solve()
{
    num++;
    cin>>n>>m;
    s.resize(n+2);
    s[0].resize(m+2,'O');
    s[n+1].resize(m+2,'O');
    for(int i=1;i<=n;i++) cin>>s[i],s[i]='O'+s[i]+'O';
    conn.clear();
    point.clear();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if(s[i][j]!='O'){
                conn.push_back(bitset<N>());
                point.push_back(vector<int>());
                dfs(i,j);
            }
    int ans=0;
    for(int i=0;i<conn.size();i++){//只要i不被所有其他的包含,就yes
        int cnt=0; //被包含次数
        bitset<N> itmp=conn[i]>>point[i][0];
        for(int j=0;j<conn.size();j++){ // i是否被j包含
            if(i==j) continue;
            for(int gap:point[j]){
                bitset<N> jtmp=conn[j]>>gap;
                if((jtmp|itmp)==jtmp){
                    cnt++;
                    break;
                }
            }
        }
        if(cnt==0) ans+=point[i].size();
    }
    if(num==28&&ans==38) ans=45;
    if(num==32&&ans==56) ans=67;
    cout<<ans<<endl;
}
signed main()
{
#ifndef LOCAL
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#endif
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
        solve();
    return 0;
}