QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#752071#7733. Cool, It’s Yesterday Four Times MoreyouyouyouWA 47ms11560kbC++202.4kb2024-11-15 21:53:032024-11-15 21:53:04

Judging History

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

  • [2024-11-15 21:53:04]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:11560kb
  • [2024-11-15 21:53:03]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = int;
const int maxn=1e3+2;
i64 dx[4]={0,1,-1,0},dy[4]={1,0,0,-1};
int a[maxn][maxn];
int l,r,up,down,n,m;
map<int,int> mp;
struct node{
    i64 x,y,d_u,r_l;
    string s;
}liantong[maxn];
char c1[4]={'D','R','L','U'};
int v[maxn][maxn],cnt;
void dfs(int x,int y)
{
    l=min(l,y);
    r=max(r,y);
    up=min(up,x);
    down=max(down,x);
    for(int i=0;i<4;++i)
    {
        int xx=x+dx[i];
        int yy=y+dy[i];
        if(xx<=0||yy<=0||xx>n||yy>m||a[xx][yy]||v[xx][yy]) continue;
        liantong[cnt].s+=c1[i];
        v[xx][yy]=1;
        dfs(xx,yy);
    }
}
bool check(int x,int y)
{
    int xx=liantong[x].x;
    int yy=liantong[x].y;
    for(int i=0;i<liantong[y].s.length();++i)
    {
        int xxx=xx+dx[mp[liantong[y].s[i]]];
        int yyy=yy+dy[mp[liantong[y].s[i]]];
        if(xxx<=0||yyy<=0||xxx>n||yyy>m||a[xxx][yyy]) 
        {
            return false;
        }
        xx=xxx;
        yy=yyy;
    }
    return true;
}
void solve()
{
    memset(a,0,sizeof(a));
    memset(v,0,sizeof(v));
    cnt=0;
    cin>>n>>m;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<=m;++j)
        {
            char c;
            cin>>c;
            if(c=='O')
            a[i][j]=1;
        }
    }
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    {
        if(!v[i][j]&&!a[i][j])
        {
            v[i][j]=1;
            cnt++;
            l=j;
            r=j;
            up=i;
            down=i;
            liantong[cnt].s="";
            dfs(i,j);
            liantong[cnt].x=i;
            liantong[cnt].y=j;
            liantong[cnt].r_l=r-l+1;
            liantong[cnt].d_u=down-up+1;
            
        }
    }
    long long ans=0;
    for(int i=1;i<=cnt;++i)
    {
        int flag=0;
    for(int j=1;j<=cnt;++j)
    {
        if(i==j) continue;
        if(liantong[i].r_l>liantong[j].r_l||liantong[i].d_u>liantong[j].d_u) 
        {
            continue;
        }if(!check(j,i)) 
        {
    
            continue;
        }
        flag=1;
        break;
    }
    if(!flag)
    { ans+=liantong[i].s.length()+1;
    }
    }
    cout<<ans<<'\n';
}
int main()
{
    int T;
    mp['D']=0;
    mp['R']=1;
    mp['L']=2;
    mp['U']=3;
    cin>>T;
    while(T--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11456kb

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: 47ms
memory: 11560kb

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
5
0
0
1
0
7
9
4
4
0
6
5
2
0
1
6
4
5
2
0
0
5
3
3
1
4
1
0
7
5
2
3
9
3
0
6
2
2
2
0
4
6
6
3
5
2
5
5
2
1
0
3
3
4
4
2
2
0
7
6
4
8
5
3
2
5
2
1
2
1
4
0
0
2
5
1
4
6
9
1
6
2
2
5
4
5
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
4
3
10
3
0
3
6
2
5
1
3
3
4
0
2
11
2
2
4
0
4
4
6
2
1
2
3
0
5
0
16
4
3
2
6
0
8
3
3
...

result:

wrong answer 7th lines differ - expected: '3', found: '5'