Submission #55286736


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
const ll one = 1;



int main(){
    int N;
    string S, T;
    cin >> N >> S >> T;

    int ms, mt;
    ms = 0;
    mt = 0;
    for (int i = 0; i < N; i++) {
        if(S[i] == 'B') ms++;
        if(T[i] == 'B') mt++;
    }

    if(ms != mt) {
        cout << -1 << endl;
        return 0;
    }

    map<string, int> dist;

    S += 'V';
    S += 'V';
    T += 'V';
    T += 'V';
    dist[S] = 0;

    queue<string> q;
    q.push(S);

    while (!q.empty()){
        string st = q.front();
        q.pop();
        int vind = 0;
        for (int i = 0; i < st.length(); i++) {
            if(st[i] == 'V') {
                vind = i;
                break;
            }           
        }        

        for (int i = 0; i < st.length() - 1; i++) {
            if(st[i] == 'V') continue;
            if(st[i+1] == 'V') continue;
            string nxt = st;
            swap(nxt[i], nxt[vind]);
            swap(nxt[i+1], nxt[vind+1]);
            if(dist.contains(nxt)) continue;
            dist[nxt] = dist[st] + 1;
            q.push(nxt);
        }
    }

    if(dist.contains(T)){
        cout << dist[T] << endl;
    }
    else{
        cout << -1 << endl;
    }


}

Submission Info

Submission Time
Task D - Go Stone Puzzle
User mel1
Language C++ 20 (gcc 12.2)
Score 425
Code Size 1579 Byte
Status AC
Exec Time 163 ms
Memory 10004 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:49:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   49 |         for (int i = 0; i < st.length(); i++) {
      |                         ~~^~~~~~~~~~~~~
Main.cpp:56:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   56 |         for (int i = 0; i < st.length() - 1; i++) {
      |                         ~~^~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 4 ms 3812 KiB
random_02.txt AC 2 ms 3560 KiB
random_03.txt AC 11 ms 4008 KiB
random_04.txt AC 1 ms 3420 KiB
random_05.txt AC 22 ms 4564 KiB
random_06.txt AC 141 ms 9168 KiB
random_07.txt AC 7 ms 3780 KiB
random_08.txt AC 1 ms 3452 KiB
random_09.txt AC 1 ms 3448 KiB
random_10.txt AC 1 ms 3508 KiB
random_11.txt AC 1 ms 3420 KiB
random_12.txt AC 1 ms 3452 KiB
random_13.txt AC 1 ms 3488 KiB
random_14.txt AC 3 ms 3660 KiB
random_15.txt AC 12 ms 4316 KiB
random_16.txt AC 37 ms 5412 KiB
random_17.txt AC 86 ms 7196 KiB
random_18.txt AC 140 ms 9004 KiB
random_19.txt AC 1 ms 3432 KiB
random_20.txt AC 1 ms 3540 KiB
random_21.txt AC 1 ms 3424 KiB
random_22.txt AC 1 ms 3480 KiB
random_23.txt AC 1 ms 3480 KiB
random_24.txt AC 1 ms 3636 KiB
random_25.txt AC 160 ms 10004 KiB
random_26.txt AC 159 ms 9932 KiB
sample_01.txt AC 1 ms 3460 KiB
sample_02.txt AC 1 ms 3444 KiB
sample_03.txt AC 163 ms 9840 KiB