CSES - HIIT Open 2024 - Results
Submission details
Task:Forgotten measurements
Sender:TyƤmiesklubi
Submission time:2024-11-16 12:56:25 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.01 sdetails
#70.01 sdetails
#80.01 sdetails
#90.01 sdetails
#100.01 sdetails
#110.01 sdetails

Code

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

static int find(string &s, char a, char b) {
    char curr = 0;
    int res = 0;
    char st = 0;
    for (auto c : s) {
        if (!st) st = c;
        if (curr != a && c == a) {
            ++res;
            curr = a;
        } else if (curr != b && c == b) {
            ++res;
            curr = b;
        }
    }
    if (curr == st) {
        --res;
    }
    return res ? res - 1 : res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    cout << find(s, 'L', 'R') + find(s, 'U', 'D') << '\n';
}

Test details

Test 1

Verdict: ACCEPTED

input
ULDRUR

correct output
2

user output
2

Test 2

Verdict: ACCEPTED

input
RULD

correct output
2

user output
2

Test 3

Verdict:

input
RULDRURDRURDLULD

correct output
7

user output
10

Test 4

Verdict:

input
LDLDRDLULULURURURULDRDLDRDRURD...

correct output
19

user output
16

Test 5

Verdict:

input
RURULDLULDRURDLULDRULURULURDLD...

correct output
470

user output
588

Test 6

Verdict:

input
DRULDLULDLULDLURDRULDRURDLURDL...

correct output
499773

user output
592928

Test 7

Verdict:

input
DLURDLULDLULDRULURULURURDLDLDR...

correct output
499383

user output
592347

Test 8

Verdict:

input
RULDLDLDRULDLDLULURULULDLURDLU...

correct output
499622

user output
592538

Test 9

Verdict:

input
RDRDRURDLDLURDRULURDLDRULDLULU...

correct output
499788

user output
592793

Test 10

Verdict:

input
LDLURDRURDRULDLULDLDRURDLULDRU...

correct output
499368

user output
592896

Test 11

Verdict:

input
DRULULDRDLDLDLURULDRDLURULULDR...

correct output
499790

user output
593032