QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#109711 | #5414. Stop, Yesterday Please No More | zhuibao | WA | 5ms | 7252kb | C++20 | 3.0kb | 2023-05-30 14:07:02 | 2023-05-30 14:07:05 |
Judging History
answer
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>pi;
//#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"Yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
//--------------------刘魔魔中魔--------------------
const int N=2e3+10;
int f[N][N],g[N][N],rpre[N][N],cpre[N][N];
int n,m,k,len;
string s;
void init()
{
for(int i=0;i<=n<<1;i++)
{
for(int j=0;j<=m<<1;j++)
{
f[i][j]=g[i][j]=rpre[i][j]=cpre[i][j]=0;
}
}
}
void tow(int &a,int &b,char ch)
{
if(ch=='U')a++;
else if(ch=='D')a--;
else if(ch=='L')b++;
else b--;
}
void solve()
{
cin>>n>>m>>k>>s;
init();
len=s.size();s=" "+s;
int a=0,b=0,c=0,d=0;
int up=0,righ=0;
for(int i=1;i<=len;i++)
{
if(s[i]=='U')up++;
if(s[i]=='D')up--;
if(s[i]=='L')righ++;
if(s[i]=='R')righ--;
a=max(a,up);b=min(b,up);
c=max(c,righ);d=min(d,righ);
}
a+=n+1;b=2*n+b;c+=m+1;d=2*m+d;
if(a>b||c>d)
{
if(k==0)
{
cout<<n*m<<endl;
}
else
{
cout<<0<<endl;
}
return;
}
int ans=0,sum=0;
for(int x=n+1,y=m+1,i=1;i<=len;i++)
{
g[x][y]|=1;
tow(x,y,s[i]);
g[x][y]|=1;
if(x>=a&&x<=b&&y>=c&&y<=d)sum++;
}
for(int i=1;i<=n<<1;i++)
{
for(int j=1;j<=m<<1;j++)
{
rpre[i][j]=rpre[i][j-1]+g[i][j];
cpre[i][j]=cpre[i-1][j]+g[i][j];
}
}
k=(b-a+1)*(d-c+1)-k;
if(sum==k)ans++;
f[n+1][m+1]=sum;
for(int j=m+1;j<=m<<1;j++)
{
for(int i=n+1;i<=n<<1;i++)
{
if(i==n+1&&j==m+1)continue;
if(i==n+1)
{
int id=c-j+m+1,did=d-j+m+2;
f[n+1][j]=f[n+1][j-1]+cpre[b][id]-cpre[a-1][id];
f[n+1][j]=f[n+1][j]-cpre[b][did]+cpre[a-1][did];
}
else
{
int id=a-i+n+1,did=b-i+n+2;
int l=c-j+m,r=d-j+m+1;
f[i][j]=f[i-1][j]+rpre[id][r]-rpre[id][l];
f[i][j]=f[i][j]-rpre[did][r]+rpre[did][l];
}
//cout<<"i= "<<i<<"j= "<<j<<' '<<f[i][j]<<endl;
if(f[i][j]==k)ans++;
}
}
cout<<ans<<endl;
}
signed main()
{
ac;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3620kb
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
Wrong Answer
time: 5ms
memory: 7252kb
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 20 99 18 15 34 240 15 0 0 13 14 18 26 16 1 19 108 20 2 1 3 7 0 30 16 21 0 8 10 9 15 0 320 11 7 3 0 0 12 0 0 0 0 0 0 22 36 51 23 7 6 4 2 48 28 8 63 0 49 13 10 4 108 10 18 44 0 15 9 0 4 30 14 99 105 10 13 17 0 66 10 11 28 0 34 56 0 14 56 90 14 0 121 3 48 30 36 13 0 30 7 15 3 11 16 0 20 34 0 38 ...
result:
wrong answer 20th numbers differ - expected: '8', found: '20'