CSES - NOI 2024 - Results
Submission details
Task:Thin Ice
Sender:Måns Edvardsson
Submission time:2024-03-06 19:24:14 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp:118:9: warning: "/*" within comment [-Wcomment]
  118 |         /*
      |          
input/code.cpp: In function 'int dp(int, int, std::vector<int>&, std::vector<std::vector<int> >&)':
input/code.cpp:11:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if (i == mem.size()-1) {
      |         ~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from input/code.cpp:2:
/usr/include/c++/11/bits/stl_algobase.h: In instantiation of 'const _Tp& std::max(const _Tp&,...

Code

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

int dp(int i, int coins, vector<int>& dur, vector<vector<int>>& mem) {

    if (mem[i][coins] != -1) {
        return mem[i][coins];
    }

    if (i == mem.size()-1) {
        return coins+1;
    }

    if (dur[i+1]-1 >= coins) {
        int r1 = -1;
        int r2 = -1;
        r1 = dp(i+1, coins, dur, mem);
        if (dur[i+1]-1 >= coins+1) {
            r2 = dp(i+1, coins+1, dur, mem);
        }
        mem[i][coins] = max(r1, r2, coins+1);
    } else {
        mem[i][coins] = coins+1;
    }

    return mem[i][coins];

}

int main() {

    int n, m;
    cin >> n >> m;

    if (n == 1) {

        vector<int> dur(m);
        int max_dur = 0;
        for (int i = 0; i < m; i++) {
            cin >> dur[i];
            if (dur[i] > max_dur) {
                max_dur = dur[i];
            }
        }

        vector<vector<int>> mem1(m, vector<int>(max_dur+1, -1));
        vector<vector<int>> mem2(m, vector<int>(max_dur+1, -1));

        int max_coins = 0;
        
        for (int i = 0; i < m; i++) {
            int res = dp(i, 0, dur, mem1);
            if (res > max_coins) {
                max_coins = res;
            }
        }

        reverse(dur.begin(), dur.end());

        for (int i = 0; i < m; i++) {
            int res = dp(i, 0, dur, mem2);
            if (res > max_coins) {
                max_coins = res;
            }
        }

        cout << max_coins << endl;

        /*

        int max_coins = 1;

        for (int i = 0; i < m; i++) {

            int p = i;
            int coins = 1;
            while (p < m-1) {

                if (dur[p+1]-1 >= coins) {
                    p++;
                    coins++;
                } else {
                    break;
                }

            }

            if (coins > max_coins) {
                max_coins = coins;
            }

        }

        reverse(dur.begin(), dur.end());

        for (int i = 0; i < m; i++) {

            int p = i;
            int coins = 1;
            while (p < m-1) {

                if (dur[p+1]-1 >= coins) {
                    p++;
                    coins++;
                } else {
                    break;
                }

            }

            if (coins > max_coins) {
                max_coins = coins;
            }

        }

        /*

        int p1 = 0;
        int p2 = 0;
        int coins_carried = 1;
        while (p1 < m) {

            p1++;
            coins_carried--;

            while (p2 < m-1) {

                if (dur[p2+1]-1 >= coins_carried) {
                    p2++;
                    coins_carried++;
                } else {
                    break;
                }

            }

            if (coins_carried > max_coins) {
                max_coins = coins_carried;
            }

        }

        reverse(dur.begin(), dur.end());

        p1 = 0;
        p2 = 0;
        coins_carried = 1;
        while (p1 < m) {

            p1++;
            coins_carried--;

            p2 = max(p2, p1);

            while (p2 < m-1) {

                if (dur[p2+1]-1 >= coins_carried) {
                    p2++;
                    coins_carried++;
                } else {
                    break;
                }

            }

            if (coins_carried > max_coins) {
                max_coins = coins_carried;
            }

        }

        */

    }

}