QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765876 | #7733. Cool, It’s Yesterday Four Times More | ChenJiarun12345 | RE | 0ms | 0kb | C++14 | 2.4kb | 2024-11-20 15:30:20 | 2024-11-20 15:30:20 |
answer
/*
缁欐瘡涓偣鎼滄椿鐐?璧版硶)+姝荤偣 bitset涓€涓?
(nm)^3/w
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define inf 0x3f3f3f3f3f3f3f3fll
#define For(i,l,r) for(int i=(l);i<=(r);++i)
#define Rof(i,l,r) for(int i=(l);i>=(r);--i)
bool M_S;
const int N=1005;
// x in [1,n], y in [1,m]
#define uid(x,y) (((x)-1)*m+(y))
// x in [-n,n], y in [-m,m]
// x+n in [0,n+n], y+n in [0,m+m]
#define UID(x,y) ((x)*(m+m+1)+(y))
int n,m,dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char s[N][N];
bitset<N> die[N*8],bit;
queue<array<int,2>> q;
bool vis[N];
void MAIN1(){
cin>>n>>m;
For(i,1,n) cin>>(s[i]+1);
int cnt=0;
For(i,1,n) For(j,1,m) cnt+=(s[i][j]=='.');
// cout<<cnt<<'\n';
// For(i,1,n){
// For(j,1,m) cout<<uid(i,j)<<' ';
// cout<<'\n';
// }
// For(i,-n,n){
// For(j,-m,m) cout<<UID(n+i,m+j)<<' ';
// cout<<'\n';
// }
For(i,1,n){
For(j,1,m){
if(s[i][j]=='O') continue;
q.push({i,j});
while(!q.empty()){
auto [x,y]=q.front();q.pop();
if(vis[uid(x,y)]) continue;
vis[uid(x,y)]=1;
For(k,0,3){
int kx=x+dx[k],ky=y+dy[k];
if(kx<1||kx>n||ky<1||ky>m||s[kx][ky]=='O'){
die[UID(n+kx-i,m+ky-j)][uid(i,j)]=1;
}
else{
q.push({kx,ky});
}
}
}
For(_,1,n*m) vis[_]=0;
}
}
int ans=0;
For(i,1,n){
For(j,1,m){
if(s[i][j]=='O') continue;
q.push({i,j});
while(!q.empty()){
auto [x,y]=q.front();q.pop();
if(vis[uid(x,y)]) continue;
vis[uid(x,y)]=1;
bit|=die[UID(n+x-i,m+y-j)];
For(k,0,3){
int kx=x+dx[k],ky=y+dy[k];
if(kx<1||kx>n||ky<1||ky>m||s[kx][ky]=='O'){
continue;
}
else{
q.push({kx,ky});
}
}
}
if(bit.count()==cnt-1) ans++;
For(_,1,n*m) vis[_]=0,bit[_]=0;
}
}
cout<<ans<<'\n';
}
void _MAIN1(){
For(i,-n,n){
For(j,-m,m){
For(_,1,n*m) die[UID(n+i,m+j)][_]=0;
}
}
}
int T;
void MAIN(){
cin>>T;
For(_,1,T) MAIN1(),_MAIN1();
}
bool M_T;
signed main(){
freopen("kangaroo.in","r",stdin);
freopen("kangaroo.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
double T_S=clock();MAIN();double T_T=clock();
cerr<<"T:"<<(T_T-T_S)/CLOCKS_PER_SEC<<"s ";
cerr<<"M:"<<(&M_S-&M_T)/1048576<<"MiB\n";
return 0;
}
/*
#1
4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO
3
1
0
0
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Dangerous Syscalls
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO