QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184505 | #5414. Stop, Yesterday Please No More | 2197181078 | RE | 0ms | 3492kb | C++14 | 1.3kb | 2023-09-20 20:15:57 | 2023-09-20 20:15:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,k,n,m;
string s;
const int N=1e3+10;
int f[N][N];
signed main()
{
cin>>t;
while(t--)
{
cin>>n>>m>>k;
memset(f,0,sizeof(0));
cin>>s;
int h=n,w=m;
int x=0,y=0;
int X=1,Y=1;
for(int i=0;i<s.length();i++)
{
if(s[i]=='U')
{
if(y>=0)h--;
y++;
if(X!=1)X--;
}
if(s[i]=='D')
{
if(y<=0)h--;
y--;
if(X!=n)X++;
}
if(s[i]=='L')
{
if(x<=0)w--;
x--;
if(Y!=1)Y--;
}
if(s[i]=='R')
{
if(x>=0)w--;
x++;
if(Y!=m)Y++;
}
}
if(!k&&h*w<=0){
cout<<n*m<<endl;
continue;
}
if(h*w<k)
{
cout<<0<<endl;
continue;
}
f[X][Y]++;f[X+h][Y+w]++;
f[X][Y+w]--;f[X+h][Y]--;
map<pair<int,int>,int>mp;
mp[{X,Y}]=1;
for(int i=s.length()-1;i>=0;i--)
{
if(s[i]=='D')X--;
if(s[i]=='U')X++;
if(s[i]=='L')Y++;
if(s[i]=='R')Y--;
if(mp[{X,Y}])continue;
mp[{X,Y}]=1;
f[X][Y]++;f[X+h][Y+w]++;
f[X][Y+w]--;f[X+h][Y]--;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(f[i][j]+k==h*w)ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3492kb
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...