Submission #953345

# Submission time Handle Problem Language Result Execution time Memory
953345 2024-03-25T20:44:22 Z OkYqsJJ Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
0 / 100
4 ms 7772 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> G , R , Y;
int n;
string s; 

int dp[61][61][61][4]; 

int brute(int i , int j , int k , int lst){
    int sz = i + j + k ;
    if (sz == n) return 0;
    if (~dp[i][j][k][lst]) return dp[i][j][k][lst]; 
    int a = 1e8 , b = 1e8 , c = 1e8;
    if (lst != 1 && i < G.size()){
        int x = 0; 
        for (int l = 0 ; l < j ; l++) if (R[l] > G[i]) x++; 
        for (int l = 0 ; l < k ; l++) if (Y[l] > G[i]) x++;
        a = brute(i+1 , j , k , 1) + x ; 
    }
    if (lst != 2 && j < R.size()){
       int x = 0;
       for (int l = 0 ; l < i ; l++) if (G[l] > R[j]) x++;
       for (int l = 0 ; l < k ; l++) if (Y[l] > R[j]) x++; 
       b = brute(i , j+1 , k , 2) + x ;
    }
    if (lst != 3 && k < Y.size()){
        int x = 0;
        for (int l = 0 ; l < i ; l++) if (G[l] > Y[k]) x++;
        for (int l = 0 ; l < j ; l++) if (R[l] > Y[k]) x++; 
        c = brute(i , j , k+1 , 3) + x;
    }
    return dp[i][j][k][lst] = min({a , b , c});
}

void doWork(){
    cin >> n >> s;
    for (int i = 0 ; i < n ; i++){
        if (s[i] == 'G') G.push_back(i);
        else if (s[i] == 'R') R.push_back(i);
        else Y.push_back(i); 
    }
    memset(dp , -1 , sizeof dp);
    cout << brute(0 , 0 , 0 , 0);
}   


signed main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    doWork(); 
}

Compilation message

joi2019_ho_t3.cpp: In function 'int brute(int, int, int, int)':
joi2019_ho_t3.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     if (lst != 1 && i < G.size()){
      |                     ~~^~~~~~~~~~
joi2019_ho_t3.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     if (lst != 2 && j < R.size()){
      |                     ~~^~~~~~~~~~
joi2019_ho_t3.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if (lst != 3 && k < Y.size()){
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 1 ms 3940 KB Output is correct
8 Correct 1 ms 3940 KB Output is correct
9 Correct 1 ms 3940 KB Output is correct
10 Incorrect 1 ms 3940 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 1 ms 3940 KB Output is correct
8 Correct 1 ms 3940 KB Output is correct
9 Correct 1 ms 3940 KB Output is correct
10 Incorrect 1 ms 3940 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3936 KB Output is correct
2 Runtime error 4 ms 7772 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Correct 2 ms 3932 KB Output is correct
3 Correct 2 ms 3932 KB Output is correct
4 Correct 3 ms 3932 KB Output is correct
5 Correct 1 ms 3932 KB Output is correct
6 Correct 1 ms 3932 KB Output is correct
7 Correct 1 ms 3940 KB Output is correct
8 Correct 1 ms 3940 KB Output is correct
9 Correct 1 ms 3940 KB Output is correct
10 Incorrect 1 ms 3940 KB Output isn't correct
11 Halted 0 ms 0 KB -