Submission #320564

#TimeUsernameProblemLanguageResultExecution timeMemory
320564caoashGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define lb lower_bound #define ub upper_bound using pi = pair<int,int>; #define f first #define s second #define mp make_pair const int MX = 200005; const int MOD = (int) (1e9 + 7); const ll INF = (ll) 1e18; int main(){ #ifdef mikey freopen("a.in", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int ops = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == s[i + 1]) { bool found = false; for (int j = i + 2; j < n; j++) { if (s[j] != s[i]) { for (int k = j; k > i; k--) { ++ops; swap(s[k], s[k - 1]); } found = true; } } if (!found) { cout << -1 << '\n'; return 0; } } } cout << ops << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...