Submission #55394282
Source Code Expand
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ ll N; string S, T; struct State{ string state; ll counts; ll loc; }; ll solve(){ if(S==T) return 0; // WA1: ここを追加 queue<State> que; map<string, bool> checked; // BFS ll cnt = 40; que.push({S, 0, N}); checked[S] = true; while(!que.empty()){ State now = que.front(); que.pop(); rep(i,N+1){ if(now.loc<=i+1&&i<=now.loc+1) continue; string str = now.state; str[now.loc] = str[i]; str[now.loc+1] = str[i+1]; str[i]='.'; str[i+1]='.'; if(str==T){ return now.counts+1; } if(!checked[str]){ checked[str]=true; que.push({str,now.counts+1,i}); } } } return -1; } int main() { cin >> N >> S >> T; S += ".."; T += ".."; ll b_in_s = 0; for(char c: S){ if(c=='B') b_in_s ++; } for(char c: T){ if(c=='B') b_in_s --; } if(b_in_s!=0){ cout << -1 << endl; return 0; } ll ans = solve(); cout << ans << endl; } #else #include <iostream> #include <vector> #include <string> #include <deque> #include <list> #include <map> #include <set> #include <unordered_set> #include <unordered_map> #include <queue> #include <stack> #include <algorithm> #include <functional> #include <utility> #include <tuple> #include <cmath> #include <limits> #include <numeric> #include <iomanip> #include <sstream> #include <fstream> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0; i<(n); i++) #define reps(i,s,n) for(ll i=(s); i<(n); i++) #define all(x) (x).begin(),(x).end() #define lb_ind(a,key) lower_bound(all((a)), (key)) - (a).begin() #define llvec(a,n) vector<ll> (a)((n)) #define yn(flg) cout<<(flg?"Yes":"No")<<endl; #endif
Submission Info
Submission Time | |
---|---|
Task | D - Go Stone Puzzle |
User | YTa09 |
Language | C++ 23 (gcc 12.2) |
Score | 425 |
Code Size | 1916 Byte |
Status | AC |
Exec Time | 135 ms |
Memory | 10248 KiB |
Compile Error
Main.cpp: In function ‘ll solve()’: Main.cpp:20:8: warning: unused variable ‘cnt’ [-Wunused-variable] 20 | ll cnt = 40; | ^~~
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 425 / 425 | ||||
Status |
|
|
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 | 3720 KiB |
random_02.txt | AC | 2 ms | 3588 KiB |
random_03.txt | AC | 10 ms | 4068 KiB |
random_04.txt | AC | 1 ms | 3504 KiB |
random_05.txt | AC | 21 ms | 4628 KiB |
random_06.txt | AC | 135 ms | 9328 KiB |
random_07.txt | AC | 6 ms | 3856 KiB |
random_08.txt | AC | 1 ms | 3480 KiB |
random_09.txt | AC | 1 ms | 3544 KiB |
random_10.txt | AC | 1 ms | 3536 KiB |
random_11.txt | AC | 1 ms | 3544 KiB |
random_12.txt | AC | 1 ms | 3504 KiB |
random_13.txt | AC | 1 ms | 3724 KiB |
random_14.txt | AC | 2 ms | 3636 KiB |
random_15.txt | AC | 11 ms | 4236 KiB |
random_16.txt | AC | 35 ms | 5372 KiB |
random_17.txt | AC | 77 ms | 7376 KiB |
random_18.txt | AC | 135 ms | 9268 KiB |
random_19.txt | AC | 1 ms | 3480 KiB |
random_20.txt | AC | 1 ms | 3508 KiB |
random_21.txt | AC | 1 ms | 3560 KiB |
random_22.txt | AC | 1 ms | 3492 KiB |
random_23.txt | AC | 1 ms | 3664 KiB |
random_24.txt | AC | 1 ms | 3628 KiB |
random_25.txt | AC | 1 ms | 3688 KiB |
random_26.txt | AC | 130 ms | 10248 KiB |
sample_01.txt | AC | 1 ms | 3508 KiB |
sample_02.txt | AC | 1 ms | 3508 KiB |
sample_03.txt | AC | 80 ms | 9860 KiB |