QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#430450#5414. Stop, Yesterday Please No MoreunclezhouRE 0ms3812kbC++201.7kb2024-06-03 20:30:452024-06-03 20:30:46

Judging History

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

  • [2024-06-03 20:30:46]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3812kb
  • [2024-06-03 20:30:45]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void solve(){
    int n,m,k;
    cin>>n>>m>>k;
    string str;
    cin>>str;
    vector<vector<int> > pre((n+5),vector<int>(m+5));
    map<pair<int,int>,int>ma;
    int lx=1,ly=1,rx=n,ry=m;
    int dx=0,dy=0;
    for(auto x:str){
        if(x=='U'){
            lx=max(lx-1,1);
            rx=max(rx-1,1);
            dx--;
        }
        else if(x=='D'){
            lx=min(lx+1,n);
            rx=min(rx+1,n);
            dx++;
        }
        else if(x=='L'){
            ly=max(ly-1,1);
            ry=max(ry-1,1);
            dy--;
        }
        else{
            ly=min(ly+1,m);
            ry=min(ry+1,m);
            dy++;
        }
    }
    lx-=dx,rx-=dx,ly-=dy,ry-=dy;
    int res=0;
    if(lx>=1&&lx<=n&&rx>=1&&rx<=n&&ly>=1&&ly<=m&&ry>=1&&ry<=m){
        res=(ry-ly+1)*(rx-lx+1);
        pre[lx][ly]+=1;
        pre[lx][ry+1]-=1;
        pre[rx+1][ly]-=1;
        pre[rx+1][ry+1]+=1;
        for(auto x:str){
            if(x=='U') lx-=1,rx-=1;
            else if(x=='D') lx+=1,rx+=1;
            else if(x=='L') ly-=1,ry-=1;
            else ly+=1,ry+=1;
            if(ma[{lx,ly}]) continue;
            ma[{lx,ly}]=1;
            pre[lx][ly]+=1;
            pre[lx][ry+1]-=1;
            pre[rx+1][ly]-=1;
            pre[rx+1][ry+1]+=1;
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            pre[i][j]+=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1];
            if(pre[i][j]==res-k) ans++;
        }
    }
    cout<<ans<<'\n';
    return;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

详细

Test #1:

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

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: