QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#475160#6736. Alice and Bobyudiao_vickyWA 0ms3500kbC++111.3kb2024-07-13 12:01:262024-07-13 12:01:26

Judging History

你现在查看的是最新测评结果

  • [2024-07-13 12:01:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3500kb
  • [2024-07-13 12:01:26]
  • 提交

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();
    }

}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3500kb

input:

1

output:

-1

result:

wrong answer 1st numbers differ - expected: '1', found: '-1'