QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#552414#7733. Cool, It’s Yesterday Four Times MoreHongMeilingWA 1ms3744kbC++143.7kb2024-09-07 22:40:412024-09-07 22:40:41

Judging History

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

  • [2024-09-07 22:40:41]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3744kb
  • [2024-09-07 22:40:41]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
const int mn=1000;

int T,n,m;
char Ar[mn+3];
inline int tow(int i,int j) {
    return (i-1)*m+j;
}
inline char a(int i,int j) {
    return Ar[(i-1)*m+j];
}
struct Kangaroo{
    int x,y;
    bool to[mn+3];
    bool win;
}kan[mn+3];int tot=0;
queue<pair<int,int>>q;
const int tox[5]={0,-1,1,0,0};
const int toy[5]={0,0,0,-1,1};
bool OK(int x,int y) {
    return x>=1 && x<=n && y>=1 && y<=m;
}
pair<int,int> order[mn+3];int tord=0;//访问顺序
int low[mn+3],high[mn+3];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("Kangaroo.in","r",stdin);
    #endif
    srand(time(0));
    cin>>T;
    while(T--) {
        tot=0;
        memset(Ar,0,sizeof(Ar));

        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            for(int j=1;j<=m;j++) {
                cin>>Ar[(i-1)*m+j];
                if(Ar[(i-1)*m+j]=='.') {
                    kan[++tot].x=i;
                    kan[tot].y=j;
                    kan[tot].win=false;
                }
            }
        }

        for(int k=1;k<=tot;k++) {
            //bfs
            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {
                    kan[k].to[tow(i,j)]=false;
                }
            }
            kan[k].to[tow(kan[k].x,kan[k].y)]=true;
            q.push(make_pair(kan[k].x,kan[k].y));

            while(!q.empty()) {
                int x=q.front().first,y=q.front().second;
                q.pop();
                for(int dir=1;dir<=4;dir++) {
                    int nx=x+tox[dir],ny=y+toy[dir];
                    if(OK(nx,ny) && a(nx,ny)=='.' && !kan[k].to[tow(nx,ny)]) {
                        kan[k].to[tow(nx,ny)]=true;
                        q.push(make_pair(nx,ny));
                    }
                }
            }
        }


        int ans=0;
        for(int k=1;k<=tot;k++) {
            int x=kan[k].x,y=kan[k].y;
            tord=0;
            for(int i=1;i<=n;i++) {
                low[i]=n+1,high[i]=0;
                for(int j=1;j<=m;j++) {
                    if(OK(i,j) && kan[k].to[tow(i,j)]) {
                        low[i]=min(low[i],j);
                        high[i]=max(high[i],j);
                    }
                }
                if(low[i]<=n) order[++tord]=make_pair(i-x,low[i]-y);
                if(high[i]>low[i]) order[++tord]=make_pair(i-x,high[i]-y);
            }
            random_shuffle(order+1,order+tord+1);
            //先访问边上的点

            int lsttop=tord;
            for(int i=1;i<=n;i++) {
                for(int j=1;j<=m;j++) {
                    if(OK(i,j) && kan[k].to[tow(i,j)] &&
                       low[i]<j && j<high[i]) {
                        order[++tord]=make_pair(i-x,j-y);
                    }
                }
            }
            random_shuffle(order+lsttop+1,order+tord+1);
            /*for(int i=1;i<=tord;i++) 
                cout<<order[i].first<<order[i].second<<endl;
            cout<<" "<<k<<endl;*/

            for(int k2=1;k2<=tot+1;k2++) {
                if(k2==tot+1) {
                    ans++;
                    break;
                }

                if(k==k2) continue;
                for(int d=1;d<=tord;d++) {
                    int nx=kan[k2].x+order[d].first,
                        ny=kan[k2].y+order[d].second;
                    //if(k==4&&k2==2) cout<<nx<<ny<<endl;
                    if(!OK(nx,ny) ||
                       !kan[k2].to[tow(nx,ny)])
                        goto nxt;//k2被打败了
                }
                break;//k2无法打败
                nxt:;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 1ms
memory: 3744kb

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:

3
0
0
2
1
1
3
0
0
1
0
7
9
4
4
0
6
5
2
0
1
6
2
5
2
0
0
5
3
3
1
4
1
0
7
5
2
3
7
3
0
6
2
2
2
0
4
6
6
3
3
2
3
5
2
1
0
3
3
4
4
2
2
0
7
6
4
8
5
3
2
5
2
1
2
1
1
0
0
2
5
1
4
6
6
1
6
2
2
1
4
5
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
4
3
8
3
0
3
5
2
5
1
3
3
4
0
2
11
2
2
4
0
4
4
6
2
1
1
3
0
5
0
16
4
3
1
6
0
8
3
3
1...

result:

wrong answer 23rd lines differ - expected: '4', found: '2'