QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89429#5414. Stop, Yesterday Please No MoreIanD#AC ✓99ms39760kbC++144.6kb2023-03-20 03:23:252023-03-20 03:23:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-20 03:23:26]
  • 评测
  • 测评结果:AC
  • 用时:99ms
  • 内存:39760kb
  • [2023-03-20 03:23:25]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair

#define MAXN 1010

int n, m, k, l;
string s;

bool vis[2*MAXN][2*MAXN];
int prex[2*MAXN][2*MAXN];
int prey[2*MAXN][2*MAXN];

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {

    cin >> n >> m >> k >> s;
    rep(i, 0, 2*n+1) rep(j, 0, 2*m+1) vis[i][j] = false;

    pii xbounds = mp(0, n-1);
    pii ybounds = mp(0, m-1);
    int posx = 0;
    int posy = 0;

    vis[n][m] = true;
    for (char c : s) {
        if (c == 'D') {
            // move grid up, eats bottom
            // eats posx + n-1;
            xbounds.second = min(xbounds.second, posx+n-2);
            posx--;
        } else if (c == 'U') {
            // eats top... posx
            xbounds.first = max(xbounds.first, posx+1);
            posx++;
            //cout << "here" << endl;
        } else if (c == 'L') {
            // eats left... posy
            ybounds.first = max(ybounds.first, posy+1);
            posy++;
        } else if (c == 'R') {
            // eats right.. posy + m-1
            ybounds.second = min(ybounds.second, posy+m-2);
            posy--;
        }
        int indx = posx + n;
        int indy = posy + m;
        if (indx >= 0 && indy >= 0 && indx <= 2*n && indy <= 2*m) {
            vis[indx][indy] = true;
        }
    }
    if (xbounds.first > xbounds.second || ybounds.first > ybounds.second) {
        if (k == 0) {
            cout << n*m << '\n';
        } else {
            cout << 0 << '\n';
        }
        continue;
    }
    //cout << xbounds.first << ' ' << xbounds.second << ' ' << ybounds.first << ' ' << ybounds.second << endl;



    rep(i, 0, 2*n+1) {
        prex[i][0] = 0;
        if (vis[i][0]) prex[i][0] = 1;
        rep(j, 1, 2*m+1) {
            prex[i][j] = prex[i][j-1];
            if (vis[i][j]) prex[i][j]++;
        }
    }

    rep(j, 0, 2*m+1) {
        prey[0][j] = 0;
        if (vis[0][j]) prey[0][j] = 1;
        rep(i, 1, 2*n+1) {
            prey[i][j] = prey[i-1][j];
            if (vis[i][j]) prey[i][j]++;
        }
    }

    int beforeeating = (xbounds.second-xbounds.first+1)*(ybounds.second-ybounds.first+1);

    int numeaten = 0;
    rep(i, xbounds.first, xbounds.second+1) rep(j, ybounds.first, ybounds.second+1) {
        if (vis[i+n][j+m]) numeaten++;
    }

    int lastizero = numeaten;
    int out = 0;

    rep(i, 0, n) {
        if (i != 0) {
            // shift up
            numeaten = lastizero;
            // get rid of (xbounds.second-(i-1)) x [ybounds.first, ybounds.second]
            numeaten -= prex[xbounds.second-(i-1)+n][ybounds.second+m];
            if (ybounds.first+m != 0) {
                numeaten += prex[xbounds.second-(i-1)+n][ybounds.first-1+m];
            }

            // add in (xbounds.first-i) x [ybounds.first, ybounds.second]
            numeaten += prex[xbounds.first-i+n][ybounds.second+m];
            if (ybounds.first+m != 0) {
                numeaten -= prex[xbounds.first-i+n][ybounds.first-1+m];
            }

            lastizero = numeaten;
        }
        rep(j, 0, m) {
            if (j != 0) {
                // shift left
                // get rid of [xbounds.first-i, xbounds.second-i] x (ybounds.second-(j-1))
                numeaten -= prey[xbounds.second-i+n][ybounds.second-(j-1)+m];
                if (xbounds.first-i+n != 0) {
                    numeaten += prey[xbounds.first-i-1+n][ybounds.second-(j-1)+m];
                }

                // add in [xbounds.first-i, xbounds.second-i] x (ybounds.first-j)
                numeaten += prey[xbounds.second-i+n][ybounds.first-j+m];
                if (xbounds.first-i+n != 0) {
                    numeaten -= prey[xbounds.first-i-1+n][ybounds.first-j+m];
                }
            }
        // hole starts at (i, j)
        
        // if hole starts at (0, 0)

        // then I query [xbounds.first, xbounds.second] x [ybounds.first, ybounds.second]

        // if hole starts at (0, 1)

        // then I query [xbounds.first, xbounds.second] x [ybounds.first-1, ybounds.second-1] 
            //cout << i << ' ' << j << ' ' << numeaten << endl;
            if (beforeeating-numeaten == k) {
                out++;
                //cout << i << ' ' << j << endl;
            }
        }
    }

    cout << out << '\n';



    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3464kb

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: 0
Accepted
time: 8ms
memory: 5892kb

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
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...

result:

ok 1060 numbers

Test #3:

score: 0
Accepted
time: 77ms
memory: 39032kb

input:

1
1000 1000 979065
DDUULULUDULLULLDLUULURRLDURLRDLRRUURUUUDLRLUUDUUDUDLLDDDULU

output:

958416

result:

ok 1 number(s): "958416"

Test #4:

score: 0
Accepted
time: 85ms
memory: 38856kb

input:

1
1000 1000 943471
LRLDLURLDLRDRDUULULRDDLLRURDUURLLDDLDLDDLLLUUURLDRUDRLLUUUUUDLUUDLURURRDLRLRRRLULRRULURLRRDLDRLUDRRLDDLUDRRLLUDLLLRDULRRRRLDUUDRDLULUUUUDRRDULUDLLUUDLDURDRRLRRLDRLDDRURURLUULRRLDLLRLRDRRUULDLDLULLDLLRULLRUULURDURRLUUDUULLULDLRUDDLRLRLLUDDDLLLUDRRLDDULRRURRDURDDRDLLULRLULURLRDLLURD...

output:

889224

result:

ok 1 number(s): "889224"

Test #5:

score: 0
Accepted
time: 97ms
memory: 39704kb

input:

1
1000 1000 315808
LLRURURRDDDULLDDUDRDLRLLLDDDLUDRDURLDULRLRULUUDLUULUUDULLLLDDURLDUULUUDLLDLLDRUDUULRLLRLRUURLRLULLDDLLDUDLLRUUDRLDLUULDLLDRRRURDULLDRRRDURURDRLDURURUDLURLDURRLRRUDUDURDRLRRRDLRRURLURUDRRLDLRULLDLUURDURLURLLRDLRDRUURURDRUDUUUDLRRLUDLUUDUDDRRDUULUUDDRLLULDUUDRURRDRLULRLULDURLURUDLLD...

output:

426

result:

ok 1 number(s): "426"

Test #6:

score: 0
Accepted
time: 84ms
memory: 38860kb

input:

1
1000 1000 986018
LLULDRRRDDURRUDRUURRRDDLUUDUULRULRDULLD

output:

972180

result:

ok 1 number(s): "972180"

Test #7:

score: 0
Accepted
time: 89ms
memory: 38916kb

input:

1
1000 1000 945431
DDRRURUUDLDULLDLDDLRULDLLDDRRLUDRLUURRLDRDLURUURRRRLRURLURULLLDRDDDRRRLDLDRLRDDUURRURDDDLRUURLUURLRDUDDDLLDUURLDLUDLLRRDUUDRLUULLUULDLURRUDLUURLRLRURDUDRRRDRLRUDLLLLURLULRLRLRRDDUDLRLDUUUULUDLLURRLURRDLRURRRULDDLLLRLRDLUDLLDDRULDUULRDDUUDDUDLURDULLDUDDLULRULDRLDDULDULLUDLULUDRURRR...

output:

893000

result:

ok 1 number(s): "893000"

Test #8:

score: 0
Accepted
time: 94ms
memory: 39716kb

input:

1
1000 1000 460035
RDDUURDULDDLDDLDDLDRRULLRLUURLURRRDRUDDDRDLDLDULUDLRLLRRLRRURRRDLRLUDRDURULDRRDDDDDDLRLDULUULDUDRLLUUUURUUDRURLRRULDRDRUUUUULULRURDDRLRULLLRDRRULUDDUDDLLLRDRUULUUDDRLURDLDURRDLRRLDRRUDLUULRDLURULLDLRLLDDURDUDLDULDLLRULRDLRLUULLUDRUDDDLRRDULULLRUURLUURRLLLLRLDRURLLRLDRRDDDRLUUUUDUL...

output:

417

result:

ok 1 number(s): "417"

Test #9:

score: 0
Accepted
time: 85ms
memory: 38908kb

input:

1
1000 1000 992010
LLLLLDLDRRLUDRR

output:

1999

result:

ok 1 number(s): "1999"

Test #10:

score: 0
Accepted
time: 81ms
memory: 38892kb

input:

1
1000 1000 919600
LLDLRUDRLURRUDRDRRDLRUDLRRRUUULDLDURDDDRUURRRLLURULDRLRLULLULDRULULRLRRRURLDDDRUUULUDLLLLRRLLRDDRDULUDLRLRLDRLUDUDURRULUULLDULUULDLLDRDULUDLDULDDUULDDRRURDRDULRRLDRRDUURURRLUUUDRRLDRRDDLULRDDLDLLRLRLLLRULUUUURRRLDLRUDRRLRURDRLDULLLUDRULLDLDRRUUDLRRLLRLDDLUDLRLRRURUUDUULUDURDURRLUU...

output:

944

result:

ok 1 number(s): "944"

Test #11:

score: 0
Accepted
time: 99ms
memory: 39760kb

input:

1
1000 1000 804351
DLRLDLLLLUDRDURRLDDRRLRUULURURDDDRDLRUDDULRRLLULURDRUUDRURRLURRRDRURRDRLULRDLRRDRRDDUDLUDLDULRUURRLRUUDRLDDRDDUUDULUULUUUDLRURULLRDUUDDDRRLDRUDDUUDRURLRDRUDLRLDDRRLLRLRDUDDULLULRLLDDUDDDUULDULLRRULULDUUULUDRRDRLUDLRRDDUDLRRDDLDLDRUULRRRRRLRLULLRDDRDDDULDRRURUDDLURLRLURLRDRULUDULUU...

output:

640000

result:

ok 1 number(s): "640000"