# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978930 | 2024-05-10T03:43:33 Z | irmuun | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 500 ms | 452 KB |
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int dist(string s,string t){//t->s int res=0; for(int i=0;i<s.size();i++){ for(int j=i;j<t.size();j++){ if(t[j]==s[i]){ for(int k=i;k<j;k++){ res++; swap(t[k],t[k+1]); } break; } } } return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin>>n; string s; cin>>s; string t=s; sort(all(t)); vector<char>ch={'R','G','Y'}; int ans=1e9; do{ bool ok=true; for(int i=1;i<n;i++){ if(t[i-1]==t[i]){ ok=false; } } if(!ok) continue; ans=min(ans,dist(s,t)); }while(next_permutation(all(t))); if(ans==1e9) ans=-1; cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 6 ms | 452 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 6 ms | 452 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Execution timed out | 1094 ms | 348 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Incorrect | 6 ms | 452 KB | Output isn't correct |
6 | Halted | 0 ms | 0 KB | - |