Code Submission Evaluation System Login

CSES - HIIT Open 2018

HIIT Open 2018

Contest start:2018-05-26 11:00:00
Contest end:2018-05-26 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard | Statistics


History
2018-05-26 15:59:39
Task:Letter Game
Sender:Wave of Technology
Submission time:2018-05-26 15:59:39
Status:READY
Result:WRONG ANSWER

Show test data

Compiler report

input/code.cpp: In function 'll solve()':
input/code.cpp:23:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
input/code.cpp: In function 'int main()':
input/code.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (res.size() != i) { continue; }
         ~~~~~~~~~~~^~~~
input/code.cpp:100:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (res.size() != i) { continue; }
         ~~~~~~~~~~~^~~~

Code

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

const ll INF = 1000000000000000LL;

ll n;

template<typename T>
void print_vector(vector<T> & v) {
  for (auto x : v) {
    cout << x << " ";
  }
}

ll solve() {
  ll n, m;
  cin >> n >> m;

}


bool test(string s) {
  bool  bfound = false;
  for (auto c : s) {
    if (c=='B') { bfound = true; }
    if (bfound && c == 'A') { return false;}
  }
  return true;
}

int main() {

  cin.tie(NULL);
  std::ios::sync_with_stdio(false);


  ll n;

  cin >> n;
  string s;
  cin >> s;

  if (n==1) {
    cout << "0\n";
    return 0;
  }
  if (n==2) {
    for (char c : s) {
      if (c=='A') {
	cout << "0\n";
	return 0;
      }
      if (c=='B') {
	cout << "-1\n";
	return 0;
      }
    }
  }


  n = 2*n;
  
  vector<string> res;

  for (int i=0; i<1000; i++) {

    int xpos = 0;
    
    for (int j=0; j<n; j++) {
      if (s[j] == '.') {
	xpos = j;
	break;
      }
    }


    for (int j=0; j<xpos; j++) {
      if (s[j] == 'B' && s[j+1] == 'B') {
	swap(s[j], s[xpos]);
	swap(s[j+1], s[xpos+1]);
	res.push_back(s);
	break;
      }
    }
    if (res.size() != i) { continue; }

    for (int j=xpos; j<n-1; j++) {
      if (s[j] == 'A' && s[j+1] == 'A') {
	swap(s[j], s[xpos]);
	swap(s[j+1], s[xpos+1]);
	res.push_back(s);
	break;
      }
    }
    
    if (res.size() != i) { continue; }


    while(true) {
      int j = rand() % (n-1);
      //      cout << j << " " << xpos << endl;
      if (abs(j-xpos) >=2) {
	swap(s[j], s[xpos]);
	swap(s[j+1], s[xpos+1]);
	res.push_back(s);
	break;
      }
    }

    if (test(res.back())) { break; }

  }

  if (!test(res.back())) { cout << -1 << endl; return 0; }
  cout << res.size() << endl;

  for (auto ss : res) {
    cout << ss << endl;
  }
  return 0;
}