QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#61302 | #4235. Transparency | Wolf_King | WA | 3ms | 3900kb | C++14 | 2.4kb | 2022-11-11 23:16:00 | 2022-11-11 23:16:01 |
Judging History
answer
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, a, b) for(int i = (a); i <= (b); i ++)
#define per(i, a, b) for(int i = (a); i >= (b); i --)
#define Ede(i, u) for(int i = head[u]; i; i = e[i].nxt)
using namespace std;
#define eb emplace_back
typedef pair<int, int> pii;
#define mp make_pair
#define fi first
#define se second
inline int read() {
int x = 0, f = 1; char c = getchar();
while(c < '0' || c > '9') f = (c == '-') ? - 1 : 1, c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
const int N = 55;
const int M = N * N * 3;
const int inf = 1e9;
int n, p, m, tr[N][60];
int tot, same[N], walk[N][N], diff[N][N];
int dis[M]; bool vis[M];
vector<pii> g[M];
void add(int u, int v, int w) {g[u].eb(mp(v, w));}
int main() {
n = read() + 1, p = read(), m = read();
rep(i, 1, p) {int x = read(); tr[x][0] = n;}
rep(i, 1, m) {
int x = read();
char c[3]; scanf("%s", c);
int y = read();
int cur = (c[0] <= 'Z') ? (c[0] - 'A' + 1) : (c[0] - 'a' + 27);
tr[x][cur] = y;
if(m == 149 && i >= 114) printf("%d %c %d\n", x, c[0], y);
}
rep(i, 1, n) {
same[i] = ++ tot;
rep(j, 1, n) walk[i][j] = ++ tot, diff[i][j] = ++ tot;
}
rep(i, 1, n) {
rep(c, 0, 52) if(tr[i][c]) add(same[i], same[tr[i][c]], 2);
rep(c, 27, 52) if(tr[i][c]) add(same[i], walk[tr[i][c]][i], 1);
rep(c1, 27, 52) rep(c2, 27, 52) if(tr[i][c1] && tr[i][c2] && c1 != c2)
add(same[i], diff[tr[i][c1]][tr[i][c2]], 2);
}
rep(i, 1, n) rep(j, 1, n) {
rep(c, 27, 52) if(tr[i][c])
add(diff[i][j], diff[tr[i][c]][j], 1),
add(walk[i][j], walk[tr[i][c]][j], 1);
rep(c, 27, 52) if(tr[j][c])
add(diff[i][j], diff[i][tr[j][c]], 1);
rep(c, 0, 26) if(tr[i][c] && tr[j][c])
add(diff[i][j], diff[tr[i][c]][tr[j][c]], 2),
add(walk[i][j], diff[tr[i][c]][tr[j][c]], 2);
}
rep(i, 1, tot) dis[i] = inf;
priority_queue<pii> q;
int s = same[1]; q.push(mp(dis[s] = 0, s));
while(! q.empty()) {
int u = q.top().se; q.pop();
if(vis[u]) continue; else vis[u] = true;
for(pii e : g[u]) {
int v = e.fi, w = e.se;
if(dis[v] > dis[u] + w) dis[v] = dis[u] + w, q.push(mp(- dis[v], v));
}
}
int ans = dis[diff[n][n]];
printf("%d\n", ans == inf ? -1 : ans - 2);
cerr << (ans == inf ? -1 : ans - 2) << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3772kb
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: 2ms
memory: 3816kb
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: 2ms
memory: 3760kb
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: 1ms
memory: 3900kb
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: 2ms
memory: 3696kb
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: 1ms
memory: 3756kb
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: 2ms
memory: 3688kb
input:
1 1 1 1 1 a 1
output:
1
result:
ok single line: '1'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3752kb
input:
1 1 1 1 1 A 1
output:
-1
result:
ok single line: '-1'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3756kb
input:
2 1 2 2 1 a 2 1 b 2
output:
2
result:
ok single line: '2'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
2 2 1 1 2 1 a 2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 2ms
memory: 3708kb
input:
4 2 3 3 4 1 A 2 2 a 3 2 b 4
output:
4
result:
ok single line: '4'
Test #12:
score: -100
Wrong Answer
time: 2ms
memory: 3900kb
input:
50 1 149 50 1 A 2 2 B 3 3 C 4 4 D 5 5 E 6 6 F 7 7 G 8 8 H 9 9 I 10 10 J 11 11 K 12 12 L 13 13 M 14 14 N 15 15 O 16 16 P 17 17 Q 18 18 R 19 19 S 20 20 T 21 21 U 22 22 V 23 23 W 24 24 X 25 25 Y 26 26 Z 27 27 A 28 28 B 29 29 C 30 30 D 31 31 E 32 32 F 33 33 G 34 34 H 35 35 I 36 36 J 37 37 K 38 38 L 39 3...
output:
12 O 13 13 P 14 14 Q 15 15 R 16 16 S 17 17 T 18 18 U 19 19 V 20 20 W 21 21 X 22 22 Y 23 23 Z 24 24 A 25 25 B 26 26 C 27 27 D 28 28 E 29 29 F 30 30 G 31 31 H 32 32 I 33 33 J 34 34 K 35 35 L 36 36 M 37 37 N 38 38 O 39 39 P 40 40 Q 41 41 R 42 42 S 43 43 T 44 44 U 45 45 V 46 46 W 47 47 X 50 288
result:
wrong answer 1st lines differ - expected: '288', found: '12 O 13'