CSES - HIIT Open 2024 - Results
Submission details
Task:Forgotten measurements
Sender:Barren plateau
Submission time:2024-11-16 13:22:08 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#30.00 sdetails
#40.00 sdetails
#50.00 sdetails
#60.04 sdetails
#70.04 sdetails
#80.04 sdetails
#90.04 sdetails
#100.04 sdetails
#110.04 sdetails

Code

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

int main() {
    string s;
    cin>>s;
    int horSum=0;
    int parsa=0;
    char cur='A';
    int len = 0;
    for (int i = 0; i < (int)s.size();i++) {
        if (s[i]==cur) {
            len++;
        } else if (s[i]=='U' || s[i]=='D') continue;
        else {
            parsa = max(parsa,len);
            horSum += len;
            len = 1;
            cur = s[i];
        }
    }
    horSum+=len;
    parsa = max(parsa, len);
    cur='A';
    len = 0;
    for (int i=0; i<(int)s.size();i++) {
        if (s[i]=='U' || s[i]=='D') continue;
        if (s[i]!=cur && cur!='A') break;
        cur=s[i];
        len++;
    }
    for (int i=(int)s.size()-1;i>0;i--) {
        if (s[i]=='U' || s[i]=='D') continue;
        if (s[i]!=cur) break;
        len++;
    }
    parsa = max(parsa,len);
    horSum -= parsa;

    int verSum = 0;
    parsa = 0;
    cur = 'A';
    len = 0;

    for (int i = 0; i < (int)s.size();i++) {
        if (s[i]==cur) {
            len++;
        } else if (s[i]=='L' || s[i]=='R') continue;
        else {
            parsa = max(parsa,len);
            verSum += len;
            len = 1;
            cur=s[i];
        }
    }
    verSum += len;
    parsa = max(parsa,len);
    
    for (int i=0; i<(int)s.size();i++) {
        if (s[i]=='L' || s[i]=='R') continue;
        if (s[i]!=cur) break;
        len++;
    }
    
    parsa = max(parsa,len);
    verSum -= parsa;

    cout << horSum + verSum << "\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
11

Test 4

Verdict:

input
LDLDRDLULULURURURULDRDLDRDRURD...

correct output
19

user output
31

Test 5

Verdict:

input
RURULDLULDRURDLULDRULURULURDLD...

correct output
470

user output
980

Test 6

Verdict:

input
DRULDLULDLULDLURDRULDRURDLURDL...

correct output
499773

user output
999955

Test 7

Verdict:

input
DLURDLULDLULDRULURULURURDLDLDR...

correct output
499383

user output
999954

Test 8

Verdict:

input
RULDLDLDRULDLDLULURULULDLURDLU...

correct output
499622

user output
999961

Test 9

Verdict:

input
RDRDRURDLDLURDRULURDLDRULDLULU...

correct output
499788

user output
999967

Test 10

Verdict:

input
LDLURDRURDRULDLULDLDRURDLULDRU...

correct output
499368

user output
999962

Test 11

Verdict:

input
DRULULDRDLDLDLURULDRDLURULULDR...

correct output
499790

user output
999954