QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703896#5414. Stop, Yesterday Please No MorePoonYaPatWA 0ms5776kbC++141.7kb2024-11-02 18:49:052024-11-02 18:49:29

Judging History

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

  • [2024-11-02 18:49:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5776kb
  • [2024-11-02 18:49:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n,m,k,sz_x,sz_y;
int cnt[1005][1005];
bool vis[1005][1005];

void add(int x1, int y1) {
    int x2=x1+sz_x, y2=y1+sz_y;
    ++cnt[x1][y1];
    --cnt[x2+1][y1];
    --cnt[x1][y2+1];
    ++cnt[x2+1][y2+1];
}

void solve() {
    cin>>n>>m>>k;
    for (int i=0; i<=n+3; ++i) for (int j=0; j<=m+3; ++j) cnt[i][j]=vis[i][j]=0;
    string s; cin>>s;
    int miX=0,maX=0,miY=0,maY=0,curX=0,curY=0;
    int sz=s.size();
    for (int i=0; i<sz; ++i) {
        if (s[i]=='U') --curX;
        if (s[i]=='D') ++curX;
        if (s[i]=='R') ++curY;
        if (s[i]=='L') --curY;
        miX=max(miX,-curX);
        miY=max(miY,-curY);
        maX=max(maX,curX);
        maY=max(maY,curY);
    }

    //all out of bound
    if (miX>=n || maX>=n || miY>=m || maY>=m) {
        if (k==0) cout<<n*m<<"\n";
        else cout<<0<<"\n";
        return;
    }

    // (miX+1,miY+1) to (n-maX,n-maY)
    sz_x=n-maX-miX-1;
    sz_y=m-maY-miY-1;

    curX=miX+1; curY=miY+1;
    vis[curX][curY]=true;
    add(curX,curY);

    for (int i=0; i<sz; ++i) {
        if (s[i]=='U') --curX;
        if (s[i]=='D') ++curX;
        if (s[i]=='R') ++curY;
        if (s[i]=='L') --curY;
        if (vis[curX][curY]) continue;
        vis[curX][curY]=true;
        add(curX,curY);
    }

    int ans=0;
    for (int i=1; i<=n; ++i) {
        for (int j=1; j<=m; ++j) {
            cnt[i][j]+=cnt[i-1][j]+cnt[i][j-1]-cnt[i-1][j-1];
            if ((sz_x+1)*(sz_y+1)-cnt[i][j] == k) ++ans;
        }
    }

    cout<<ans<<"\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t; cin>>t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0ms
memory: 5776kb

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:

11
11
20
99
18
15
34
0
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
8
63
22
49
13
10
4
108
10
18
44
0
15
9
0
4
30
14
99
105
10
14
17
0
66
10
11
28
52
34
56
33
14
56
90
14
0
121
3
48
30
36
13
0
30
7
8
3
11
16
45
20
34
0
38...

result:

wrong answer 1st numbers differ - expected: '228', found: '11'