Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
#include
using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; if(n > 30) { cout << "GRESHKA" << endl; return 0; } queue
q_s; queue
q; q_s.push(s); q.push(0); unordered_map
visited; visited[s] = true; while(!q_s.empty()) { string t = q_s.front(); q_s.pop(); int cekor = q.front(); q.pop(); bool ok = true; int i = 0, j = n - 1; while(i < j) { if(t[i] != t[j]) { ok = false; break; } i++; j--; } if(ok) { cout << cekor << endl; return 0; } for(int i = 0; i + 1 < n; i++) { swap(t[i], t[i + 1]); if(!visited[t]) { visited[t] = true; q_s.push(t); q.push(cekor + 1); } swap(t[i], t[i + 1]); } } cout << "GRESHKA" << endl; return 0; }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)