CSES - Aalto Competitive Programming 2024 - wk3 - Mon - Results
Submission details
Task:Wario kart I
Sender:odanobunaga8199
Submission time:2024-09-16 16:55:45 +0300
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In lambda function:
input/code.cpp:25:12: error: 'pos' was not declared in this scope; did you mean 'pow'?
   25 |         if(pos + delta < track_length){
      |            ^~~
      |            pow
input/code.cpp:41:18: warning: unused variable 'found' [-Wunused-variable]
   41 |             bool found = false;
      |                  ^~~~~
input/code.cpp: In function 'int main()':
input/code.cpp:70:35: error: 'pos' was not declared in this scope; did you mean 'pow'?
   70 |             if(has_boost_in_range(pos, delta)){
      |                                   ^~~
      |                                   pow

Code

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(m);
    for(auto &x: a){
        cin >> x;
        x *= 100;
    }
    sort(a.begin(), a.end());
    int track_length = n * 100;
    if(k ==0){
        cout << 0;
        return 0;
    }
    auto has_boost_in_range = [&](int current_pos, int delta) -> bool{
        if(delta ==0){
            return false;
        }
        if(pos + delta < track_length){
            int lower = current_pos +1;
            int upper = current_pos + delta;
            int idx = lower_bound(a.begin(), a.end(), lower) - a.begin();
            if(idx < m && a[idx] <= upper){
                return true;
            }
            else{
                return false;
            }
        }
        else{
            int lower1 = current_pos +1;
            int upper1 = track_length -1;
            int lower2 = 0;
            int upper2 = (current_pos + delta) % track_length;
            bool found = false;
            if(lower1 <= upper1){
                int idx1 = lower_bound(a.begin(), a.end(), lower1) - a.begin();
                if(idx1 < m && a[idx1] <= upper1){
                    return true;
                }
            }
            if(lower2 <= upper2){
                int idx2 = lower_bound(a.begin(), a.end(), lower2) - a.begin();
                if(idx2 < m && a[idx2] <= upper2){
                    return true;
                }
            }
            return false;
        }
    };
    int current_pos =0;
    bool boost_active = false;
    for(int sec=1; sec<=k; sec++){
        int delta;
        if(boost_active){
            delta =200;
        }
        else{
            delta =100;
        }
        int new_pos = (current_pos + delta) % track_length;
        bool next_boost_active = false;
        if(!boost_active){
            if(has_boost_in_range(pos, delta)){
                next_boost_active = true;
            }
        }
        current_pos = new_pos;
        boost_active = next_boost_active;
    }
    cout << current_pos;
}