# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978936 | 2024-05-10T03:57:31 Z | irmuun | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++17 | 500 ms | 456 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=j-1;k>=i;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)); 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(t,s)); }while(next_permutation(all(t))); if(ans==1e9) ans=-1; cout<<ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 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 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 9 ms | 348 KB | Output is correct |
7 | Correct | 6 ms | 348 KB | Output is correct |
8 | Correct | 12 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 5 ms | 456 KB | Output is correct |
12 | Correct | 10 ms | 452 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 456 KB | Output is correct |
15 | Correct | 6 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 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 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 9 ms | 348 KB | Output is correct |
7 | Correct | 6 ms | 348 KB | Output is correct |
8 | Correct | 12 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 5 ms | 456 KB | Output is correct |
12 | Correct | 10 ms | 452 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 456 KB | Output is correct |
15 | Correct | 6 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Execution timed out | 1036 ms | 348 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Execution timed out | 1080 ms | 348 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 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 | Correct | 5 ms | 348 KB | Output is correct |
6 | Correct | 9 ms | 348 KB | Output is correct |
7 | Correct | 6 ms | 348 KB | Output is correct |
8 | Correct | 12 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 5 ms | 456 KB | Output is correct |
12 | Correct | 10 ms | 452 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 3 ms | 456 KB | Output is correct |
15 | Correct | 6 ms | 348 KB | Output is correct |
16 | Correct | 0 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Execution timed out | 1036 ms | 348 KB | Time limit exceeded |
19 | Halted | 0 ms | 0 KB | - |