QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#475160 | #6736. Alice and Bob | yudiao_vicky | WA | 0ms | 3500kb | C++11 | 1.3kb | 2024-07-13 12:01:26 | 2024-07-13 12:01:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// #define int long long
unordered_map<string,int> d;
int n;
int bfs(string a,string b){
queue <string> q;
q.push(a);
d[a]=0;
while(!q.empty()){
string c=q.front();
q.pop();
if(c==b){
return d[c];
}
// cout<<c<<endl;
string t="";
for (int i=0;i<c.size();i++){
int x=c[i]-'0'+i;
if(x>=n){
x-=n;
}
t += (x+'0');
}
if(!d.count(t)){
d[t]=d[c]+1;
q.push(t);
}
t=c[c.size()-1]+c.substr(0, c.size()-1);
if(!d.count(t)){
d[t]=d[c]+1;
q.push(t);
}
t=c.substr(1, c.size()-1)+c[0];
if(!d.count(t)){
d[t]=d[c]+1;
q.push(t);
}
}
return -1;
}
void solve()
{
string b="";
string a="";
cin>>n;
for (int i=0;i<n;i++){
char c;
cin>>c;
b+=c;
a+="0";
}
// cout<<a<<" "<<b<<endl;
cout<<bfs(a,b)<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3500kb
input:
1
output:
-1
result:
wrong answer 1st numbers differ - expected: '1', found: '-1'