QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370264#4235. TransparencyInfinityNS#WA 5ms10772kbC++143.0kb2024-03-28 23:58:502024-03-28 23:58:52

Judging History

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

  • [2024-03-28 23:58:52]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:10772kb
  • [2024-03-28 23:58:50]
  • 提交

answer

#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ld long double
using namespace std;

const int N=53,L=26;
int nxt[N][N];
int dist[N][N][2][2];
int main(){
    memset(dist,-1,sizeof dist);
    for(int i=0;i<N;i++)for(int j=0;j<N;j++)nxt[i][j]=-1;
    int n,p,t;
    scanf("%i %i %i",&n,&p,&t);
    vector<bool> fin(n);
    for(int i=0;i<p;i++){
        int x;
        scanf("%i",&x);
        fin[x-1]=1;
    }
    for(int i=0;i<t;i++){
        int a,b;
        string s;
        cin >> a >> s >> b;
        a--;b--;
        int ind=0;
        if(s[0]>='a'&&s[0]<='z')ind=s[0]-'a';
        else ind=s[0]-'A'+L;
        nxt[a][ind]=b;
    }
    vector<queue<pair<pair<int,int>,pair<bool,bool>>>> qs(N*N*4);
    auto up=[&](int a,int b, bool same, bool must,int di){
        if(dist[a][b][same][must]==-1||dist[a][b][same][must]>di){
            //printf("%i %i  %i  %i   %i\n",a,b,same?1:0,must?1:0,di);
            dist[a][b][same][must]=di;
            qs[di].push({{a,b},{same,must}});
        }
    };
    up(0,0,1,0,0);
    for(int t=0;t<N*N*4;t++){
        while(qs[t].size()){
            auto x=qs[t].front();
            int a=x.f.f,b=x.f.s;
            bool same=x.s.f;
            bool must=x.s.s;
            qs[t].pop();
            if(dist[a][b][same][must]!=t)continue;
            if(fin[a]&&fin[b]&&!same&&!must){
                printf("%i\n",t);
                return 0;
            }
            if(same){
                assert(!must);
                assert(a==b);
                for(int k=L;k<2*L;k++){
                    if(nxt[a][k]!=-1&&nxt[b][k]!=-1){
                        up(nxt[a][k],nxt[b][k],1,0,t+2);
                    }
                }
                for(int k1=0;k1<L;k1++){
                    if(nxt[a][k1]!=-1){
                        for(int k2=0;k2<L;k2++){
                            if(nxt[b][k2]!=-1){
                                if(k1==k2){
                                    up(nxt[a][k1],nxt[b][k2],1,0,t+2);
                                }
                                else{
                                    up(nxt[a][k1],nxt[b][k2],0,0,t+2);
                                }
                            }
                        }
                        up(a,nxt[b][k1],0,1,t+1);
                    }
                }
            }
            else{
                // Uppercase
                for(int k=L;k<2*L;k++){
                    if(nxt[a][k]!=-1&&nxt[b][k]!=-1){
                        up(nxt[a][k],nxt[b][k],0,0,t+2);
                    }
                }
                for(int k=0;k<L;k++){
                    if(nxt[a][k]!=-1&&!must){
                        up(nxt[a][k],b,same,must,t+1);
                    }
                    if(nxt[b][k]!=-1){
                        up(a,nxt[b][k],same,must,t+1);
                    }
                }
            }
        }
    }
    printf("-1\n");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10552kb

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: 5ms
memory: 10772kb

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: 0ms
memory: 10552kb

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'