Submission #950179

#TimeUsernameProblemLanguageResultExecution timeMemory
950179ezzzayGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
0 / 100
0 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ss second #define ff first #define pb push_back const int N=3e5+5; int b[N]; int a[N]; map<string,int>mp; signed main(){ int n; cin>>n; string s; cin>>s; mp[s]=1; queue<string>q; q.push(s); while(!q.empty()){ string a=q.front(); q.pop(); for(int i=0;i<n-1;i++){ if(a[i]==a[i+1]){ cout<<mp[a]-1; return 0; } } for(int i=0;i<n-1;i++){ string b=a; swap(b[i],b[i+1]); if(mp[b]==0 ){ mp[b]=mp[a]+1; q.push(b); } } } cout<<-1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...