Submission #98276

#TimeUsernameProblemLanguageResultExecution timeMemory
98276someone_aaGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
15 / 100
124 ms164984 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 410; const int inf = 100000000; int dp[maxn][maxn][maxn][3]; int n, arr[maxn]; string code; vector<int>v[3]; int main() { cin>>n; cin>>code; for(int i=0;i<code.length();i++) { if(code[i] == 'R') arr[i + 1] = 0; else if(code[i] == 'G') arr[i + 1] = 1; else arr[i + 1] = 2; v[arr[i+1]].pb(i + 1); } for(int i=0;i<=v[0].size()+1;i++) { for(int j=0;j<=v[1].size()+1;j++) { for(int k=0;k<=v[2].size()+1;k++) { for(int l=0;l<=2;l++) { dp[i][j][k][l] = inf; } } } } dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0; for(int c0=0;c0<=v[0].size();c0++) { for(int c1=0;c1<=v[1].size();c1++) { for(int c2=0;c2<=v[2].size();c2++) { for(int last=0;last<=2;last++) { if(dp[c0][c1][c2][last] == inf) continue; for(int nxt=0;nxt<=2;nxt++) { if(last != 0 && nxt == 0 && c0 < v[0].size()) { dp[c0+1][c1][c2][0] = min(dp[c0+1][c1][c2][0], dp[c0][c1][c2][last] + abs(v[0][c0] - (c0+c1+c2+1))); } else if(last != 1 && nxt == 1 && c1 < v[1].size()) { dp[c0][c1+1][c2][1] = min(dp[c0][c1+1][c2][1], dp[c0][c1][c2][last] + abs(v[1][c1] - (c0+c1+c2+1))); } else if(last != 2 && nxt == 2 && c2 < v[2].size()) { dp[c0][c1][c2+1][2] = min(dp[c0][c1][c2+1][2], dp[c0][c1][c2][last] + abs(v[2][c2] - (c0+c1+c2+1))); } } } } } } int result = min(min(dp[v[0].size()][v[1].size()][v[2].size()][0], dp[v[0].size()][v[1].size()][v[2].size()][1]), dp[v[0].size()][v[1].size()][v[2].size()][2]); if(result == inf) { cout<<"-1\n"; return 0; } cout<<(result/2)<<"\n"; return 0; }

Compilation message (stderr)

joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:18:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<code.length();i++) {
                 ~^~~~~~~~~~~~~~
joi2019_ho_t3.cpp:25:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<=v[0].size()+1;i++) {
                 ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<=v[1].size()+1;j++) {
                     ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:27:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k=0;k<=v[2].size()+1;k++) {
                         ~^~~~~~~~~~~~~~~
joi2019_ho_t3.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int c0=0;c0<=v[0].size();c0++) {
                  ~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:38:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int c1=0;c1<=v[1].size();c1++) {
                      ~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:39:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int c2=0;c2<=v[2].size();c2++) {
                          ~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:43:56: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         if(last != 0 && nxt == 0 && c0 < v[0].size()) {
                                                     ~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:46:61: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         else if(last != 1 && nxt == 1 && c1 < v[1].size()) {
                                                          ~~~^~~~~~~~~~~~~
joi2019_ho_t3.cpp:49:61: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         else if(last != 2 && nxt == 2 && c2 < v[2].size()) {
                                                          ~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...