QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630933#5414. Stop, Yesterday Please No Morekans2298WA 8ms3976kbC++173.0kb2024-10-11 21:02:222024-10-11 21:02:22

Judging History

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

  • [2024-10-11 21:02:22]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3976kb
  • [2024-10-11 21:02:22]
  • 提交

answer

#include<cstdio>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int f[256][2];
int main()
{
     int t,ti;
     //freopen("input.in","r",stdin);
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     f['U'][0]=-1,f['U'][1]=0;
     f['D'][0]=1,f['D'][1]=0;
     f['L'][0]=0,f['L'][1]=-1;
     f['R'][0]=0,f['R'][1]=1;
     cin>>t;
     for (ti=1;ti<=t;++ti)
     {
     int n,m,k,l,x1,y1,x2,y2,dx=0,dy=0,i,j;
     string ss;
     cin>>n>>m>>k;
     cin>>ss;
     l=ss.length();
     x1=1,y1=1,x2=n,y2=m;
     auto okay=[n,m](const int x,const int y) -> bool { return (x>=1 && x<=n && y>=1 && y<=m); };
     for (auto ch:ss)
          {
          dx+=f[ch][0],dy+=f[ch][1];
          if (ch=='U')
               {
               x1-=1,x2-=1;
               if (x1<1 && x2>=1) x1=1;
               }
          else if (ch=='D')
               {
               x1+=1,x2+=1;
               if (x2>n && x1<=n) x2=n;
               }
          else if (ch=='L')
               {
               y1-=1,y2-=1;
               if (y1<1 && y2>=1) y1=1;
               }
          else if (ch=='R')
               {
               y1+=1,y2+=1;
               if (y2>m && y1<=m) y2=m;
               }
          }
     if (okay(x1,y1) && okay(x2,y2))
          {
          //cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<"\n";
          //cout<<x1-dx<<" "<<y1-dy<<" "<<x2-dx<<" "<<y2-dy<<"\n";
          }
     else //rest 0
          {
          if (k==0) cout<<n*m<<"\n";
               else cout<<"0\n";
          continue;
          }
     x1-=dx,y1-=dy;
     x2-=dx,y2-=dy;
     int alive=(x2-x1+1)*(y2-y1+1);
     vector<vector<int>> a(2*n+1,vector<int>(2*m+1,0));
     vector<vector<int>> a2(2*n+1,vector<int>(2*m+1,0));
     auto b=[&a,n,m](int x,int y){ return &a[x+n][y+m]; };
     auto s=[&a2,n,m](int x,int y){ return &a2[x+n][y+m]; };
     auto ob=[n,m](int x,int y) -> bool { return (x>=-(n-1) && x<=(n-1) && y>=-(m-1) && y<=(m-1)); };
     i=0,j=0;
     *b(i,j)=1;
     for (auto ch:ss)
          {
          i-=f[ch][0],j-=f[ch][1];
          if (ob(i,j)) *b(i,j)=1;
          }
     // for (i=-(n-1);i<=(n-1);++i)
     //      {
     //      for (j=-(m-1);j<=(m-1);++j)
     //           cout<<*b(i,j);
     //      cout<<"\n";
     //      }
     for (i=-(n-1);i<=(n-1);++i)
          for (j=-(m-1);j<=(m-1);++j)
               *s(i,j)=*s(i-1,j)+*s(i,j-1)-*s(i-1,j-1)+*b(i,j);
     int ans=0;
     for (int x3=-(n-1);x3<=(n-1);++x3)
          for (int y3=-(m-1);y3<=(m-1);++y3)
               {
               int x0=x1-x3,y0=y1-y3;
               if (okay(x0,y0))
                    {
                    int xr=x3+(x2-x1),yr=y3+(y2-y1);
                    int dead=*s(xr,yr)-*s(x3-1,yr)-*s(xr,y3-1)+*s(x3-1,y3-1);
                    if (alive-dead==k)
                         {
                         ++ans;
                         //cout<<x0<<" "<<y0<<"\n";
                         }
                    }
               }
     cout<<ans<<"\n";
     }
     return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 8ms
memory: 3976kb

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
8
2
2
3
7
0
30
16
21
0
8
10
9
15
5
320
11
7
3
0
0
12
0
11
0
0
14
0
22
36
51
23
7
6
4
2
48
28
5
63
22
49
13
10
4
108
10
18
9
0
15
9
0
4
30
14
99
105
10
14
0
0
66
10
11
28
52
34
56
33
14
56
0
14
0
121
3
48
30
36
13
0
0
7
8
3
11
16
45
20
34
0
38
...

result:

wrong answer 58th numbers differ - expected: '8', found: '5'