QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#208341#4235. Transparencyucup-team1209#WA 12ms62764kbC++202.9kb2023-10-09 14:31:252023-10-09 14:31:25

Judging History

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

  • [2023-10-09 14:31:25]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:62764kb
  • [2023-10-09 14:31:25]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
using pi = pair <int, int> ; 

cs int N = 55; 
int n, m, P; 
bool ed[N];
vector <pi> e[N];
int id(char c) {
    if('A' <= c && c <= 'Z') return c - 'A' + 1;
    return c - 'a' + 27; 
}
int c[N][N][N][3], nd; 
cs int M = 2e6; 
bool fin[M]; 
int d[M], ex[M];
struct dat {
    int x, y, k, o;
}; 
vector <int> q[M];

void push(int t, int x) {
    if(d[x] > t) {
        d[x] = t;
        q[t].pb(x);
    }
}

int main() { 
    #ifdef zqj
    freopen("1.in","r",stdin);
    #endif
    cin >> n >> P >> m;
    for(int i = 1; i <= P; i++) {
        int x; 
        cin >> x;
        ed[x] = 1; 
    } 
    for(int i = 1; i <= m; i++) {
        int x; 
        char c[3];
        int y; 
        scanf("%d%s%d", & x, c, & y);
        e[x].pb({y, id(c[0])});
    }
    vector <dat> info; 
    for(int i = 1; i <= n; i++)
    for(int j = 1; j <= n; j++)
    for(int k = 0; k <= 26; k++)
    for(int o = 0; o < 3; o++) {
        c[i][j][k][o] = nd; 
        if(ed[i] && ed[j] && k == 0 && o) fin[nd] = 1; 
        info.pb({i, j, k, o});
        nd ++;
    }
    memset(d, 0x3f, sizeof d);
    q[0].pb(c[1][1][0][0]);
    d[c[1][1][0][0]] = 0;
    for(int t = 0; t < M; t++) 
    for(auto x : q[t]) {
        auto [i, j, k, o] = info[x]; 
        if(ex[x]) continue; ex[x] = 1; 
        if(fin[x]) {
            cout << t << '\n';
            return 0; 
        }
        if(o == 2) {
            assert(k == 0);
            for(auto [y, c2] : e[j]) 
            if(c2 > 26) push(t + 1, c[i][y][k][o]);
            continue; 
        }
        if(k == 0) {
            if(o == 0) {
                assert(i == j);
                for(auto [x, c1] : e[i])
                for(auto [y, c2] : e[j]) 
                if(c1 <= 26 && c2 > 26) {
                    push(t + 2, c[x][y][c1][1]);
                }
                for(auto [x, c1] : e[i])
                for(auto [y, c2] : e[j]) 
                if(c1 > 26 && c2 > 26 && x != y) {
                    push(t + 2, c[x][y][0][1]);
                }
                for(auto [x, c1] : e[i])
                    push(t + 2, c[x][x][0][0]);
                for(auto [y, c2] : e[j]) 
                    if(c2 > 26) push(t + 1, c[i][y][k][2]);
            }
            for(auto [x, c1] : e[i])
            for(auto [y, c2] : e[j]) 
            if(c1 <= 26 && c2 <= 26 && c1 == c2) {
                push(t + 2, c[x][y][k][o | (x != y)]);
            }
        }
        else {
            assert(o);
            for(auto [y, c2] : e[j]) 
            if(c2 == k) push(t + 1, c[i][y][0][o]);
        }
        if(o) {
            for(auto [x, c1] : e[i]) 
            if(c1 > 26) push(t + 1, c[x][j][k][o]);
            for(auto [y, c2] : e[j]) 
            if(c2 > 26) push(t + 1, c[i][y][k][o]);
        }
    }
    cout << -1 << '\n';
    return 0; 
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 10ms
memory: 62764kb

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: 12ms
memory: 61552kb

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: 0
Accepted
time: 4ms
memory: 61996kb

input:

5 2 5
1
5
1 i 2
2 c 3
3 p 4
4 c 1
1 I 5

output:

4

result:

ok single line: '4'

Test #4:

score: 0
Accepted
time: 8ms
memory: 61960kb

input:

8 2 96
4
8
1 x 2
1 y 5
2 A 3
3 A 4
4 A 2
5 A 6
6 A 7
7 A 8
8 A 5
5 B 2
6 B 2
7 B 2
8 B 2
5 C 2
6 C 2
7 C 2
8 C 2
5 D 2
6 D 2
7 D 2
8 D 2
5 E 2
6 E 2
7 E 2
8 E 2
5 F 2
6 F 2
7 F 2
8 F 2
5 G 2
6 G 2
7 G 2
8 G 2
5 H 2
6 H 2
7 H 2
8 H 2
5 I 2
6 I 2
7 I 2
8 I 2
5 J 2
6 J 2
7 J 2
8 J 2
5 K 2
6 K 2
7 K 2
8...

output:

24

result:

ok single line: '24'

Test #5:

score: 0
Accepted
time: 11ms
memory: 62056kb

input:

4 1 4
1
1 d 2
2 A 3
3 A 4
4 d 1

output:

-1

result:

ok single line: '-1'

Test #6:

score: 0
Accepted
time: 10ms
memory: 61872kb

input:

7 1 8
1
1 d 2
2 A 3
3 A 4
4 d 1
1 A 5
5 d 6
6 d 7
7 A 1

output:

8

result:

ok single line: '8'

Test #7:

score: 0
Accepted
time: 3ms
memory: 61728kb

input:

1 1 1
1
1 a 1

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 7ms
memory: 61400kb

input:

1 1 1
1
1 A 1

output:

-1

result:

ok single line: '-1'

Test #9:

score: -100
Wrong Answer
time: 11ms
memory: 62764kb

input:

2 1 2
2
1 a 2
1 b 2

output:

-1

result:

wrong answer 1st lines differ - expected: '2', found: '-1'