Submission #953066

#TimeUsernameProblemLanguageResultExecution timeMemory
953066OkYqsJJGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
20 / 100
1039 ms800 KiB
#include <bits/stdc++.h> using namespace std; int ans = 1e9; int n; string b; void brute(int i , int x , int y , int z , string a){ if (i == n) { int ops = 0; for (int i = 0 ; i < n ; i++){ for (int j = i ; j < n ; j++){ if (a[j] == b[i]) { for (int k = j ; k > i ; k--) {swap(a[k] , a[k-1]); ops++; } break; } } //cout << a << '\n'; } ans = min(ans , ops); return; } if (a.back() != 'G' && x > 0) brute(i+1 , x-1 , y , z , a + 'G'); if (a.back() != 'R' && y > 0) brute(i+1 , x , y-1 , z , a + 'R'); if (a.back() != 'Y' && z > 0) brute(i+1 , x , y , z - 1 , a + 'Y'); } signed main(){ cin >> n >> b; int x = 0 ,y = 0 ,z =0 ; for (auto i : b) {if (i == 'G') x++; else if (i == 'R') y++; else z++;} brute(0 , x , y , z , ""); cout << (ans == 1e9 ? -1 : ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...