QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692880 | #5414. Stop, Yesterday Please No More | lselegies | TL | 1ms | 9952kb | C++14 | 1.6kb | 2024-10-31 15:09:48 | 2024-10-31 15:10:02 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5,M=1e6+5;
int ans[N][N],vis[N][N],a[M],base[N][N];
int sum;
signed main()
{
int t;
cin>>t;
while(t--)
{
int n,m,K;
cin>>n>>m>>K;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
ans[i][j]=0;
vis[i][j]=0;
base[i][j]=0;
}
string s;
cin>>s;
int len=s.size();
s=" "+s;
for (int i=1;i<=len;i++)
a[i]=0;
int lr=0,ud=0,ll=0,rr=0,uu=0,dd=0;
for (int i=1;i<=len;i++)
{
if (s[i]=='U')
{
a[i]=1;
ud++;
uu=max(uu,ud);
}
else if (s[i]=='D')
{
a[i]=2;
ud--;
dd=min(dd,ud);
}
else if (s[i]=='L')
{
a[i]=3;
lr--;
ll=min(ll,lr);
}
else
{
a[i]=4;
lr++;
rr=max(rr,lr);
}
}
sum=0;
//cout<<uu<<' '<<dd<<' '<<ll<<' '<<rr<<endl;
for (int i=1+uu;i<=n+dd;i++)
for (int j=1-ll;j<=m-rr;j++)
sum++;
//sum=(n+dd)
//cout<<sum<<endl;
if (K==0)
{
cout<<n*m<<endl;
continue;
}
else if (sum<K)
{
cout<<0<<endl;
continue;
}
int x=1+uu,y=1-ll;
base[x][y]=1;
for(int i=1;i<=len;i++)
{
if (a[i]==1) x--;
if (a[i]==2) x++;
if (a[i]==3) y--;
if (a[i]==4) y++;
if (base[x][y]) continue;
base[x][y]=1;
}
for (int i=1+uu;i<=n+dd;i++)
for (int j=1-ll;j<=m-rr;j++)
for (int k=1;k<=n;k++)
for (int l=1;l<=m;l++)
{
int dx=i-x,dy=j-y;
if (base[k][l]) ans[k+dx+1][l+dy+1]++;
}
int res=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if(sum-ans[i][j]==K) res++;
cout<<res<<endl;
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9952kb
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
Time Limit Exceeded
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:
228 11 18 99 12 15 32 240 5 0 0 11 9 18 13 0 12 17 96 6 0 0 0 36 8 26 11 13 0 0 9 9 9 0 320 1 1 0 0 0 6 0 11 0 0 6 0 22 18 51 10 7 6 1 1 48 28 8 63 20 36 0 5 1 96 9 0 44 0 2 1 0 4 30 13 80 105 8 13 17 0 66 7 11 28 39 15 42 30 6 56 90 14 0 121 0 48 0 14 8 0 30 4 8 2 6 0 40 20 34 0 17 0 16 0 52 0 9 14...