CSES - Datatähti 2025 alku - Results
Submission details
Task:Kortit I
Sender:drvilepis
Submission time:2024-10-28 10:58:54 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:13:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i < rooms.length(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~~
input/code.cpp:68:48: error: expected '}' at end of input
   68 |     std::cout << steps << " " << coins << "\n";
      |                                                ^
input/code.cpp:5:12: note: to match this '{'
    5 | int main() {
      |            ^

Code

#include <algorithm>
#include <iostream>
#include <string>

int main() {
    int n;
    std::cin >> n;
    std::string rooms;
    std::cin >> rooms;

    int robot;

    for (int i = 0; i < rooms.length(); ++i) {
        if (rooms[i] == 'R') robot = i;
    }

    int coins = 0;
    int steps = 0;

    bool done = false;
    while (!done) {
        int i = 1;

        int lb = robot;
        int ub = rooms.length()-robot-1;

        int sign = (ub-lb)/std::abs(ub-lb);
        int found = false;
        for (; i <= std::min(lb, ub); ++i) {
            if (rooms[robot-i] == '*') {
                if (rooms[robot+i] == '*') {
                    done = true;
                    break;
                } else {
                    rooms[robot] = '.';
                    robot -= i;
                    coins++;
                    steps += i;
                    found = true;
                    break;
                }
            } else if (rooms[robot+i] == '*') {
                rooms[robot] = '.';
                robot += i;
                coins++;
                steps += i;
                found = true;
                break;
            }
        }
        if (done || found) continue;

        for (;i <= std::max(lb, ub); ++i) {
            if (rooms[robot+i*sign] == '*') {
                rooms[robot] = '.';
                robot += i*sign;
                coins++;
                steps += i;
                found = true;
                break;
            }
        }
        if (!found) {
            done = true;
        }
    }

    std::cout << steps << " " << coins << "\n";