正文
增加 7 行删除 7 行
51 行未改动52535455565758596011 行未改动727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141154 行未改动51 行未改动namespace dij{int dis[L],n;bitset <L> vis;il void solve(int _n,int s=1){n=_n;prque(pii,greater) q; rep(i,0,n+1) dis[i]=inf;11 行未改动il void solve(){read(n); rep(i,1,n) read(a[i].s),read(a[i].c);string tmp; int tot=1;rep(i,1,n){tmp=""; // prefixrep(j,0,(int)a[i].s.size()-1) tmp+=a[i].s[j],to.count("0"+tmp) || (to["0"+tmp]=++tot);tmp=""; // suffixrpe(j,(int)a[i].s.size()-1,0) tmp=a[i].s[j]+tmp,to.count("1"+tmp) || (to["1"+tmp]=++tot);}string s,t; bool op; int sl,tl;rep(i,1,n) p[1].pb(to["0"+a[i].s],a[i].c),p[1].pb(to["1"+a[i].s],a[i].c);for(auto [_s,id]:to){s=_s.substr(1,(int)_s.size()-1),op=_s[0]=='1';if(s==(tmp=s,reverse(all(tmp)),tmp)) {p[id].pb(tot+1,0); continue;}rep(i,1,n){t=a[i].s,sl=s.size(),tl=t.size();if(sl==tl) {s==(tmp=t,reverse(all(tmp)),tmp) && (p[id].pb(tot+1,a[i].c),1); continue;}if(op){if(sl>tl) reverse(all(t)), s.find(t)==0 && (p[id].pb(to["1"+s.substr(tl,sl-tl)],a[i].c),1), reverse(all(t));else reverse(all(s)), t.rfind(s)==tl-sl && (p[id].pb(to["0"+t.substr(0,tl-sl)],a[i].c),1), reverse(all(s));}else{if(sl>tl) reverse(all(t)), s.rfind(t)==sl-tl && (p[id].pb(to["0"+s.substr(0,sl-tl)],a[i].c),1), reverse(all(t));else reverse(all(s)), t.find(s)==0 && (p[id].pb(to["1"+t.substr(sl,tl-sl)],a[i].c),1), reverse(all(s));}}}dij::solve(tot+1);write(dij::dis[tot+1]>=inf-712 ? -1ll : dij::dis[tot+1]);}```4 行未改动51 行未改动52535455565758596011 行未改动727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141154 行未改动51 行未改动namespace dij{int dis[L],n;bitset <L> vis;il void solve(int _n,int s=1){n=_n;prque(pii,greater) q; rep(i,0,n+1) dis[i]=inf;11 行未改动il void solve(){read(n); rep(i,1,n) read(a[i].s),read(a[i].c);string tmp; int tot=1;rep(i,1,n){tmp=""; // prefixrep(j,0,(int)a[i].s.size()-1) tmp+=a[i].s[j],to.count("0"+tmp) || (to["0"+tmp]=++tot);tmp=""; // suffixrpe(j,(int)a[i].s.size()-1,0) tmp=a[i].s[j]+tmp,to.count("1"+tmp) || (to["1"+tmp]=++tot);}string s,t; bool op; int sl,tl;rep(i,1,n) p[1].pb(to["0"+a[i].s],a[i].c),p[1].pb(to["1"+a[i].s],a[i].c);for(auto [_s,id]:to){s=_s.substr(1,(int)_s.size()-1),op=_s[0]=='1';if(s==(tmp=s,reverse(all(tmp)),tmp)) {p[id].pb(tot+1,0); continue;}rep(i,1,n){t=a[i].s,sl=s.size(),tl=t.size();if(sl==tl) {s==(tmp=t,reverse(all(tmp)),tmp) && (p[id].pb(tot+1,a[i].c),1); continue;}if(op){if(sl>tl) reverse(all(t)), s.find(t)==0 && (p[id].pb(to["1"+s.substr(tl,sl-tl)],a[i].c),1), reverse(all(t));else reverse(all(s)), t.rfind(s)==tl-sl && (p[id].pb(to["0"+t.substr(0,tl-sl)],a[i].c),1), reverse(all(s));}else{if(sl>tl) reverse(all(t)), s.rfind(t)==sl-tl && (p[id].pb(to["0"+s.substr(0,sl-tl)],a[i].c),1), reverse(all(t));else reverse(all(s)), t.find(s)==0 && (p[id].pb(to["1"+t.substr(sl,tl-sl)],a[i].c),1), reverse(all(s));}}}dij::solve(tot+1);write(dij::dis[tot+1]>=inf-712 ? -1ll : dij::dis[tot+1]);}```4 行未改动