Submission #164145

#TimeUsernameProblemLanguageResultExecution timeMemory
164145NucleistGrowing Vegetable is Fun 3 (JOI19_ho_t3)C++14
5 / 100
1089 ms96940 KiB
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
map<string,ll>vis;
bool checki(string k)
{
	for (ll i = 0; i < k.size()-1; ++i)
	{
		if(k[i]==k[i+1])return false;
	}
	return true;
}
ll ans;
ll glob=INF;
int main()
{
  //flash;
	ll x;
	cin>>x;
	string sol;
	cin>>sol;
	queue<pair<string,ll>>nowi;
	nowi.push({sol,0});
	while(!nowi.empty())
	{
		auto k = nowi.front();
		nowi.pop();
		if(checki(k.first)){cout<<k.second;exit(0);}
		for (ll i = 0; i < k.first.size()-1; ++i)
		{
			string next = k.first;
			swap(next[i],next[i+1]);
			if(vis.find(next)==vis.end())
				 {
				 	vis[next]=1;
				 	nowi.push({next,k.second+1});
				 }
		}
	}
	cout<<-1;
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message (stderr)

joi2019_ho_t3.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
joi2019_ho_t3.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
joi2019_ho_t3.cpp: In function 'bool checki(std::__cxx11::string)':
joi2019_ho_t3.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i = 0; i < k.size()-1; ++i)
                 ~~^~~~~~~~~~~~
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:49:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll i = 0; i < k.first.size()-1; ++i)
                  ~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...