QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65180 | #4235. Transparency | Sorting# | WA | 4ms | 5020kb | C++ | 2.0kb | 2022-11-27 22:59:49 | 2022-11-27 22:59:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n,k,m;
vector<pair<int,int> >e[51];
int win[51];
vector<int>adj[70001];
int d[70001];
int h(int i,int j,int k){
return (i-1)*n*29+(j-1)*29+k;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> k >> m;
for(int i=1; i<=k ;i++){
int x;cin >> x;win[x]=true;
}
for(int i=1; i<=m ;i++){
int u,v;char c;
cin >> u >> c >> v;
if(c>='a' && c<='z'){
e[u].push_back({-(c-'a'+1),v});
}
else{
e[u].push_back({c-'A'+1,v});
}
}
{//building edges
for(int i=1; i<=n ;i++){//out.k = 27
adj[h(i,i,27)].push_back(h(i,i,28));
for(auto c:e[i]){
adj[h(i,i,28)].push_back(h(c.se,c.se,27));
for(auto d:e[i]){
if(c.fi==d.fi) continue;
if(c.fi>0 && d.fi>0) continue;
int nk=max(c.fi,0)+max(d.fi,0);
adj[h(i,i,28)].push_back(h(c.se,d.se,nk));
}
}
}
for(int i=1; i<=n ;i++){//out.k = 0
for(int j=1; j<=n ;j++){
for(auto c:e[i]){
adj[h(i,j,0)].push_back(h(c.se,j,max(c.fi,0)));
}
for(auto c:e[j]){
adj[h(i,j,0)].push_back(h(c.se,i,max(c.fi,0)));
}
}
}
for(int i=1; i<=n ;i++){//out.k = 0
for(int j=1; j<=n ;j++){
for(int k=1; k<=26 ;k++){
for(auto c:e[j]){
if(c.fi<0) adj[h(i,j,k)].push_back(h(i,c.se,k));
else if(c.fi==k) adj[h(i,j,k)].push_back(h(i,c.se,0));
}
}
}
}
}
int st=h(1,1,27);
for(int i=1; i<=n ;i++){
for(int j=1; j<=n ;j++){
for(int k=0; k<29 ;k++){
int id=h(i,j,k);
d[id]=1e9;
}
}
}
d[st]=0;
queue<int>q;q.push(st);
while(!q.empty()){
int x=q.front();q.pop();
for(auto c:adj[x]){
if(d[c]>d[x]+1){
d[c]=d[x]+1;
q.push(c);
}
}
}
int ans=1e9;
for(int i=1; i<=n ;i++){
for(int j=1; j<=n ;j++){
//cout << i << ' ' << j << ' ' << d[h(i,j,0)] << endl;
if(!win[i] || !win[j]) continue;
ans=min(ans,d[h(i,j,0)]);
}
}
if(ans==1e9) cout << "-1\n";
else cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 4952kb
input:
4 1 8 3 1 F 1 1 A 2 2 b 1 2 F 3 2 d 3 3 B 3 3 y 4 4 d 1
output:
10
result:
ok single line: '10'
Test #2:
score: 0
Accepted
time: 4ms
memory: 5020kb
input:
4 1 8 3 1 F 1 1 A 2 2 b 1 2 F 3 2 d 3 3 B 3 3 y 4 4 d 4
output:
-1
result:
ok single line: '-1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 4960kb
input:
5 2 5 1 5 1 i 2 2 c 3 3 p 4 4 c 1 1 I 5
output:
6
result:
wrong answer 1st lines differ - expected: '4', found: '6'