Submission #506209

#TimeUsernameProblemLanguageResultExecution timeMemory
506209sidonGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
154 ms196592 KiB
#include <bits/stdc++.h> using namespace std; #define minim(X, Y) (X = min(X, Y)) #define F(X, Y) for(int X = 0; X < Y; X++) const int Z = 202, INF = 1e9; int N, A[Z*2], DP[Z][Z][Z][3], p[3][Z*2], c[3], x, y, z; int main() { cin >> N, getchar(); F(i, N) { char v = getchar(); A[i] = (v < 82) + (v < 89); } F(i, Z) F(j, Z) F(k, Z) F(l, 3) DP[i][j][k][l] = (i || j || k) ? INF : 0; F(i, N) { if(++c[A[i]] >= Z-1) break; p[A[i]][c[A[i]]] = i + 1; F(j, i+1) F(k, i+1) { if(A[i] == 0) x = c[0], y = j, z = k; if(A[i] == 1) x = j, y = c[1], z = k; if(A[i] == 2) x = j, y = k, z = c[2]; int s = x + y + z; if(x) minim(DP[x][y][z][0], min(DP[x-1][y][z][1], DP[x-1][y][z][2]) + abs(p[0][x] - s)); if(y) minim(DP[x][y][z][1], min(DP[x][y-1][z][0], DP[x][y-1][z][2]) + abs(p[1][y] - s)); if(z) minim(DP[x][y][z][2], min(DP[x][y][z-1][0], DP[x][y][z-1][1]) + abs(p[2][z] - s)); } } int res = INF; F(i, 3) minim(res, DP[c[0]][c[1]][c[2]][i]); cout << (res == INF ? -1 : res/2); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...