QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#109708 | #5414. Stop, Yesterday Please No More | zhuibao | WA | 4ms | 6848kb | C++20 | 3.0kb | 2023-05-30 13:55:16 | 2023-05-30 13:55:19 |
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;i++)
{
for(int j=0;j<=m;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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3600kb
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: 4ms
memory: 6848kb
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 97 12 15 1 240 9 0 0 3 5 18 1 12 8 17 4 20 1 2 0 3 1 13 5 5 0 7 4 9 10 5 320 9 7 3 0 0 0 8 6 3 2 0 0 22 2 51 2 12 6 2 4 48 28 8 6 11 0 0 9 0 3 3 4 44 0 0 0 1 4 30 2 6 105 0 0 17 12 66 7 11 28 0 17 0 0 2 4 90 2 0 5 3 48 3 2 8 0 30 5 1 4 3 0 3 6 5 1 17 0 7 12 5 1 20 2 48 0 0 225 0 2 19 2 11 ...
result:
wrong answer 3rd numbers differ - expected: '20', found: '18'