QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#258063#7733. Cool, It’s Yesterday Four Times MoreSSHWA 4ms9420kbC++203.0kb2023-11-19 14:46:052023-11-19 14:46:05

Judging History

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

  • [2023-11-19 14:46:05]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:9420kb
  • [2023-11-19 14:46:05]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve();
signed main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}
#define N 7000
bitset<N> st[N];
char g[N];
int n,m,X[4]={0,0,1,-1},Y[4]={1,-1,0,0};
map<pair<int,int>,int>mp;
int idx;
int getid(int x,int y){
    return x*(m+2)+y+2500;
}
void solve(){
    idx=0;
    mp.clear();
    cin>>n>>m;
    for(int i=0;i<=n+1;i++){
        for(int j=0;j<=m+1;j++){
            g[getid(i,j)]='O';
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>g[getid(i,j)];
        }
    }
    int cnt=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(g[getid(i,j)] != 'O'){
                cnt++;
                queue<pair<int,int>> q;
                q.push({0,0});
                vector<int> vis(N);
                while(q.size()){
                    auto [dx,dy]=q.front();
                    q.pop();
                    if(vis[getid(dx,dy)])continue;
                    vis[getid(dx,dy)]=1;
                    if(g[getid(i+dx,j+dy)]=='O'){
                        st[getid(dx,dy)].set(getid(i,j),1);
                        continue;
                    }
                    for(int k=0;k<4;k++){
                        int ndx=dx+X[k];
                        int ndy=dy+Y[k];
                        if(!vis[getid(dx,dy)]){
                            q.push({ndx,ndy});
                        }
                    }
                }
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            
            if(g[getid(i,j)]!='O'){
                bitset<N> nt;
                queue<pair<int,int>> q;
                q.push({0,0});
                vector<int> vis(N);
                while(q.size()){
                    if(nt.count()==cnt-1){
                        ans++;
                        break;
                    }
                    auto [dx,dy]=q.front();
                    q.pop();
                    if(vis[getid(dx,dy)])continue;
                    vis[getid(dx,dy)]=1;
                    if(g[getid(i+dx,j+dy)]=='O'){
                        continue;
                    }
                    else{
                        nt|=st[getid(dx,dy)];
                        if(nt.count()==cnt-1){
                            ans++;
                            break;
                        }
                    }
                    for(int k=0;k<4;k++){
                        int ndx=dx+X[k];
                        int ndy=dy+Y[k];
                        if(!vis[getid(dx,dy)]){
                            q.push({ndx,ndy});
                        }
                    }
                }
                
            }
            
        }
    }
    cout<<ans<<"\n";
    for(int i=0;i<N;i++){
        st[i].reset();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 9420kb

input:

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

output:

0
1
0
0

result:

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