QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#760291#5414. Stop, Yesterday Please No Moreeinekleine18RE 0ms3548kbC++202.8kb2024-11-18 16:01:372024-11-18 16:01:39

Judging History

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

  • [2024-11-18 16:01:39]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3548kb
  • [2024-11-18 16:01:37]
  • 提交

answer

#include<bits/stdc++.h>
#include <vector>

#define int long long
constexpr int inf=1e18;
void slove(){
    int n,m,k;
    std::cin>>n>>m>>k;
    std::string s;
    std::cin>>s;
    int x=0,y=0,u=inf,d=-inf,l=inf,r=-inf;
    int dx[]={-1,1,0,0};
    int dy[]={0,0,-1,1};
    std::string dir="UDLR";
    for(auto &it:s){
        int p=0;
        for(int i=0;i<4;++i){
            if(it==dir[i]){
                p=i;
                break;
            }
        }
        x+=dx[p];
        y+=dy[p];
        u=std::min(u,x);
        d=std::max(d,x);
        l=std::min(l,y);
        r=std::max(r,y);
    }
    u=std::max(1ll,1-u);
    d=std::min(n,n-d);
    l=std::max(1ll,1-l);
    r=std::min(m,m-r);
    int cnt=std::max(0ll,d-u+1)*std::max(0ll,r-l+1);
    if(cnt<k){
        std::cout<<0<<'\n';
        return;
    }
    std::vector g(n*2+5,std::vector<int>(m*2+5));
    auto add=[&](int x,int y)->void {
        x+=n,y+=m;
        if(x<0||x>=n*2+5||y<0||y>=n*2+5) return;
        // std::cout<<x<<' '<<y<<'\n';
        g[x][y]=1;
    };
    x=1,y=1;
    add(x,y);
    for(auto &it:s){
        int p=0;
        if(it=='U') it='D';
        else if(it=='D') it='U';
        else if(it=='L') it='R';
        else if(it=='R') it='L';
        for(int i=0;i<4;++i){
            if(it==dir[i]){
                p=i;
                break;
            }
        }
        x+=dx[p];
        y+=dy[p];
        add(x,y);
    }
    for(int i=1;i<n*2+5;++i){
        for(int j=0;j<m*2+5;++j){
            g[i][j]+=g[i-1][j];
        }
    }
    for(int i=0;i<n*2+5;++i){
        for(int j=1;j<m*2+5;++j){
            g[i][j]+=g[i][j-1];
        }
    }
    // std::cout<<cnt<<' '<<u<<' '<<d<<' '<<l<<' '<<r<<'\n';
    auto query=[&](int sx,int sy)->int {
        int ex=sx+std::max(-1ll,d-u),ey=sy+std::max(-1ll,r-l);
        if(ex>=n*2+5||ey>=m*2+5) return inf;
        return g[ex][ey]-g[sx-1][ey]-g[ex][sy-1]+g[sx-1][sy-1];
    };
    int ans=0;
    for(int i=1;i<n*2+5;++i){
        for(int j=1;j<m*2+5;++j){
            // std::cout<<i<<' '<<j<<std::endl;
            int res=query(i,j);
            if(cnt-res==k){
                int px=u+(1-(i-n));
                int py=l+(1-(j-m));
                // std::cout<<i-n<<' '<<j-m<<' '<<res<<'\n';
                // std::cout<<px<<' '<<' '<<py<<'\n';
                if(px>=1&&py>=1&&px<=n&&py<=m){
                    ++ans;
                }
            }
        }
    }
    std::cout<<ans<<'\n';
}

signed main(){
#ifdef LOCAL
    std::freopen("in.txt","r",stdin);
    std::freopen("out.txt","w",stdout);
#endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int _=1;
    std::cin>>_;
    for(int i=0;i<_;++i){
        slove();
    }
}

详细

Test #1:

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

input:

3
4 5 3
ULDDRR
4 5 0
UUUUUUU
4 5 10
UUUUUUU

output:

2
20
0

result:

ok 3 number(s): "2 20 0"

Test #2:

score: -100
Runtime Error

input:

1060
19 12 0
UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL
11 1 0
UR
3 18 33
UDRLR
17 11 132
RLDRDLDRUU
6 10 13
UULUDDLRDLUUDLDD
1 15 0
D
6 20 50
D...

output:


result: