CSES - Leirikisa 2 - Results
Submission details
Task:Nautilus
Sender:DualRed
Submission time:2023-04-18 16:39:33 +0300
Language:C++ (C++20)
Status:READY
Result:66
Feedback
groupverdictscore
#1ACCEPTED29
#2ACCEPTED37
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#4ACCEPTED0.01 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#7ACCEPTED0.00 s1, 2, 3details
#8ACCEPTED0.01 s2, 3details
#9ACCEPTED0.01 s2, 3details
#10ACCEPTED0.01 s2, 3details
#11ACCEPTED0.01 s2, 3details
#12ACCEPTED0.00 s2, 3details
#13ACCEPTED0.01 s2, 3details
#14ACCEPTED0.01 s2, 3details
#15ACCEPTED0.01 s2, 3details
#16ACCEPTED0.01 s2, 3details
#17ACCEPTED0.00 s2, 3details
#18ACCEPTED0.01 s2, 3details
#19ACCEPTED0.01 s2, 3details
#20ACCEPTED0.01 s2, 3details
#21ACCEPTED0.01 s2, 3details
#22ACCEPTED0.00 s2, 3details
#23--3details
#24--3details
#25--3details
#26--3details
#27ACCEPTED0.09 s3details
#28--3details
#29--3details
#30--3details
#31--3details
#32ACCEPTED0.09 s3details
#33--3details
#34--3details
#35--3details
#36--3details
#37ACCEPTED0.06 s3details

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int R, C, M;

bool in_bounds(int r, int c){
    return r >= 0 && c >= 0 && r < R && c < C;
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> R >> C >> M;
    vector<vector<vector<bool>>> grid(2, vector<vector<bool>>(R, vector<bool>(C)));
    vector<pair<int, int>> sea;
    for(int r = 0; r < R; r++){
        for(int c = 0; c < C; c++){
            char s; cin >> s;
            if(s != '#'){
                grid[0][r][c] = true;
                sea.push_back(make_pair(r, c));
            }
        }
    }

    string signals;
    cin >> signals;
    int k = 0;
    for(char ch : signals){
        for(auto p : sea){
            int r = p.first; int c = p.second;
            grid[1-k][r][c] = false;
            if((ch == 'W' || ch == '?') && in_bounds(r, c+1) && grid[k][r][c+1]){
                grid[1-k][r][c] = true;
                continue;
            }
            if((ch == 'E' || ch == '?') && in_bounds(r, c-1) && grid[k][r][c-1]){
                grid[1-k][r][c] = true;
                continue;
            }
            if((ch == 'N' || ch == '?') && in_bounds(r+1, c) && grid[k][r+1][c]){
                grid[1-k][r][c] = true;
                continue;
            }
            if((ch == 'S' || ch == '?') && in_bounds(r-1, c) && grid[k][r-1][c]){
                grid[1-k][r][c] = true;
                continue;
            }
        }
        k = 1 - k;
    }

    int ans = 0;
    for(int r = 0; r < R; r++){
        for(int c = 0; c < C; c++){
            if(grid[k][r][c]) ans++;
        }
    }
    cout << ans << endl;
}



/*

int R, C, M;
    cin >> R >> C >> M;
    
    set<pair<int, int>> pos;
    vector<set<int>> rows(R), cols(C);
    vector<vector<bool>> grid(R, vector<bool>(C));
    for(int r = 0; r < R; r++){
        for(int c = 0; c < C; c++){
            char s; cin >> s;
            if(s == '#'){
                grid[r][c] = 1;
                rows[r].insert(c);
                cols[c].insert(r);
            }
            else pos.insert(make_pair(r, c));
        }
    }
    string signals;
    cin >> signals;

char prev = '-';
    for(char ch : signals){
        if(ch == prev && ch != '?') continue;
        prev = ch;

        set<pair<int, int>> npos;
        if(ch == 'W' || ch == '?'){
            for(auto p : pos){
                auto it = rows[p.first].upper_bound(p.second);
                if(it == rows[p.first].begin()){
                    npos.insert(make_pair(p.first, 0));
                }
                else{
                    it--;
                    npos.insert(make_pair(p.first, *it + 1));
                }
            }
        }
        if(ch == 'E' || ch == '?'){
            for(auto p : pos){
                auto it = rows[p.first].upper_bound(p.second);
                if(it == rows[p.first].end()){
                    npos.insert(make_pair(p.first, C-1));
                }
                else{
                    npos.insert(make_pair(p.first, *it - 1));
                }
            }
        }
        if(ch == 'N' || ch == '?'){
            for(auto p : pos){
                auto it = cols[p.second].upper_bound(p.first);
                if(it == cols[p.second].begin()){
                    npos.insert(make_pair(0, p.second));
                }
                else{
                    it--;
                    npos.insert(make_pair(*it + 1, p.second));
                }
            }
        }
        if(ch == 'S' || ch == '?'){
            for(auto p : pos){
                auto it = cols[p.second].upper_bound(p.first);
                if(it == cols[p.second].end()){
                    npos.insert(make_pair(R-1, p.second));
                }
                else{
                    it--;
                    npos.insert(make_pair(*it - 1, p.second));
                }
            }
        }
        pos = npos;
    }

    cout << pos.size() << "\n";
    return 0;

*/

Test details

Test 1

Group: 2, 3

Verdict: ACCEPTED

input
5 9 7
...##....
..#.##..#
..#....##
.##...#..
...

correct output
22

user output
22

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
.................................

correct output
8272

user output
8272

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
.#...#.#..#.....#.........#......

correct output
5

user output
5

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
.#...##...#...##....##.#.##..#...

correct output
1

user output
1

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
..#.#.#..###.#.#.##..########....

correct output
1

user output
1

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
.#.#.###########..#.###.######...

correct output
1

user output
1

Test 7

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100 100
##############################...

correct output
1

user output
1

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.................................

correct output
9503

user output
9503

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
#..#.##..#....##...#.##.##..#....

correct output
495

user output
495

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
#.#...######.#####.#.##...#.##...

correct output
51

user output
51

Test 11

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.#.#.###########..#.###.######...

correct output
34

user output
34

Test 12

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
##############################...

correct output
19

user output
19

Test 13

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.................................

correct output
9801

user output
9801

Test 14

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
..............#..................

correct output
7479

user output
7479

Test 15

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
#.#.........###.#..#.#..####.#...

correct output
5328

user output
5328

Test 16

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.#.#.###########..#.###.######...

correct output
127

user output
127

Test 17

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
##############################...

correct output
19

user output
19

Test 18

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.................................

correct output
10000

user output
10000

Test 19

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
..............#..................

correct output
8047

user output
8047

Test 20

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
#.#...######.#####.#.##...#.##...

correct output
3500

user output
3500

Test 21

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
.#.#.###########..#.###.######...

correct output
1228

user output
1228

Test 22

Group: 2, 3

Verdict: ACCEPTED

input
100 100 100
##############################...

correct output
43

user output
43

Test 23

Group: 3

Verdict:

input
500 500 5000
.................................

correct output
249493

user output
(empty)

Test 24

Group: 3

Verdict:

input
500 500 5000
#..#.##..#....##...#.##.##..#....

correct output
222

user output
(empty)

Test 25

Group: 3

Verdict:

input
500 500 5000
.#####....####..###...####.#.#...

correct output
1268

user output
(empty)

Test 26

Group: 3

Verdict:

input
500 500 5000
#.#####.##..#####.####..######...

correct output
805

user output
(empty)

Test 27

Group: 3

Verdict: ACCEPTED

input
500 500 5000
##############################...

correct output
349

user output
349

Test 28

Group: 3

Verdict:

input
500 500 5000
.................................

correct output
249999

user output
(empty)

Test 29

Group: 3

Verdict:

input
500 500 5000
..............#..................

correct output
197917

user output
(empty)

Test 30

Group: 3

Verdict:

input
500 500 5000
#.#.........###.#..#.#..####.#...

correct output
79550

user output
(empty)

Test 31

Group: 3

Verdict:

input
500 500 5000
#.#####.##..#####.####..######...

correct output
1221

user output
(empty)

Test 32

Group: 3

Verdict: ACCEPTED

input
500 500 5000
##############################...

correct output
1414

user output
1414

Test 33

Group: 3

Verdict:

input
500 500 5000
.................................

correct output
250000

user output
(empty)

Test 34

Group: 3

Verdict:

input
500 500 5000
..............#..................

correct output
199752

user output
(empty)

Test 35

Group: 3

Verdict:

input
500 500 5000
.#####....####..###...####.#.#...

correct output
87691

user output
(empty)

Test 36

Group: 3

Verdict:

input
500 500 5000
#.#####.##..#####.####..######...

correct output
30998

user output
(empty)

Test 37

Group: 3

Verdict: ACCEPTED

input
500 500 5000
##############################...

correct output
1440

user output
1440