Submission #584556

# Submission time Handle Problem Language Result Execution time Memory
584556 2022-06-27T14:37:49 Z Kanaifu Miners (IOI07_miners) C++14
100 / 100
183 ms 111820 KB
#include <bits/stdc++.h>

using namespace std;

int arr[100001];
int dp[100001][4][4][4][4];
int n;

int rec(int pos, char last_l, char plast_l, char last_r, char plast_r)
{
    if (pos == n)
    {
        return 0;
    }
    if (dp[pos][last_l][plast_l][last_r][plast_r] != -1)
    {
        return dp[pos][last_l][plast_l][last_r][plast_r];
    }
    int inc = 1;
    if (last_l != arr[pos] and last_l != 0)
    {
        inc++;
    }
    if (plast_l != arr[pos] and plast_l != last_l and plast_l != 0)
    {
        inc++;
    }
    dp[pos][last_l][plast_l][last_r][plast_r] = rec(pos+1, arr[pos], last_l, last_r, plast_r) + inc;

    inc = 1;
    if (last_r != arr[pos] and last_r != 0)
    {
        inc++;
    }
    if (plast_r != arr[pos] and plast_r != last_r and plast_r != 0)
    {
        inc++;
    }
    dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
    return dp[pos][last_l][plast_l][last_r][plast_r];
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin>>n;
    for (int i=0; i<n; i++)
    {
        char c;
        cin>>c;
        if (c=='M')
        {
            arr[i] = 1;
        }
        else if (c=='B')
        {
            arr[i] = 2;
        }
        else
        {
            arr[i] = 3;
        }
    }
    cout<<rec(0, 0, 0, 0, 0);
}

Compilation message

miners.cpp: In function 'int rec(int, char, char, char, char)':
miners.cpp:15:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |     if (dp[pos][last_l][plast_l][last_r][plast_r] != -1)
      |                 ^~~~~~
miners.cpp:15:25: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |     if (dp[pos][last_l][plast_l][last_r][plast_r] != -1)
      |                         ^~~~~~~
miners.cpp:15:34: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |     if (dp[pos][last_l][plast_l][last_r][plast_r] != -1)
      |                                  ^~~~~~
miners.cpp:15:42: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |     if (dp[pos][last_l][plast_l][last_r][plast_r] != -1)
      |                                          ^~~~~~~
miners.cpp:17:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         return dp[pos][last_l][plast_l][last_r][plast_r];
      |                        ^~~~~~
miners.cpp:17:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         return dp[pos][last_l][plast_l][last_r][plast_r];
      |                                ^~~~~~~
miners.cpp:17:41: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         return dp[pos][last_l][plast_l][last_r][plast_r];
      |                                         ^~~~~~
miners.cpp:17:49: warning: array subscript has type 'char' [-Wchar-subscripts]
   17 |         return dp[pos][last_l][plast_l][last_r][plast_r];
      |                                                 ^~~~~~~
miners.cpp:28:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     dp[pos][last_l][plast_l][last_r][plast_r] = rec(pos+1, arr[pos], last_l, last_r, plast_r) + inc;
      |             ^~~~~~
miners.cpp:28:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     dp[pos][last_l][plast_l][last_r][plast_r] = rec(pos+1, arr[pos], last_l, last_r, plast_r) + inc;
      |                     ^~~~~~~
miners.cpp:28:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     dp[pos][last_l][plast_l][last_r][plast_r] = rec(pos+1, arr[pos], last_l, last_r, plast_r) + inc;
      |                              ^~~~~~
miners.cpp:28:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     dp[pos][last_l][plast_l][last_r][plast_r] = rec(pos+1, arr[pos], last_l, last_r, plast_r) + inc;
      |                                      ^~~~~~~
miners.cpp:39:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |             ^~~~~~
miners.cpp:39:21: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                     ^~~~~~~
miners.cpp:39:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                              ^~~~~~
miners.cpp:39:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                                      ^~~~~~~
miners.cpp:39:62: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                                                              ^~~~~~
miners.cpp:39:70: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                                                                      ^~~~~~~
miners.cpp:39:79: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                                                                               ^~~~~~
miners.cpp:39:87: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |     dp[pos][last_l][plast_l][last_r][plast_r] = max (dp[pos][last_l][plast_l][last_r][plast_r], rec(pos+1, last_l, plast_l, arr[pos], last_r) + inc);
      |                                                                                       ^~~~~~~
miners.cpp:40:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |     return dp[pos][last_l][plast_l][last_r][plast_r];
      |                    ^~~~~~
miners.cpp:40:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |     return dp[pos][last_l][plast_l][last_r][plast_r];
      |                            ^~~~~~~
miners.cpp:40:37: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |     return dp[pos][last_l][plast_l][last_r][plast_r];
      |                                     ^~~~~~
miners.cpp:40:45: warning: array subscript has type 'char' [-Wchar-subscripts]
   40 |     return dp[pos][last_l][plast_l][last_r][plast_r];
      |                                             ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 100368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 100480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 100420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 100408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 100472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 100428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 100556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 100992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 101620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 103308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 143 ms 108984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 111820 KB Output is correct