#include "Azer.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 2005;
namespace {
V<pi> G[N];
int d[N], vis[N];
int n;
int state, last_dist;
int u, dist, code, cnt;
// state
// 0: to sent
// 1: waiting B cost
// 2: watting B for who
void send_cost(int cost) {
for(int i = 8; i >= 0; i--)
SendA(cost >> i & 1);
}
void send_who(int who) {
for(int i = 10; i >= 0; i--)
SendA(who >> i & 1);
}
void upd(int dist, int u) {
if(u == (1 << 11) - 1)
return;
assert(dist >= last_dist);
assert(!vis[u]);
d[u] = dist;
vis[u] = 1;
last_dist = dist;
for(auto [v, w]:G[u]) {
if(d[u] + w < d[v]) {
d[v] = d[u] + w;
}
}
}
void start() {
assert(state == 0);
dist = last_dist + (1 << 9) - 1, u = (1 << 11) - 1;
for(int i = 0; i < n; i++) if(!vis[i]) {
if(d[i] < dist) {
dist = d[i];
u = i;
}
}
send_cost(dist - last_dist);
state = 1;
}
} // namespace
void InitA(int _n, int A, vi u, vi v, vi c) {
n = _n;
for(int i = 0; i < A; i++) {
G[u[i]].EB(v[i], c[i]);
G[v[i]].EB(u[i], c[i]);
}
memset(d, 0x3f, sizeof(d[0]) * n);
memset(vis, 0, sizeof(vis[0]) * n);
d[0] = 0;
state = 0;
last_dist = 0;
code = 0;
cnt = 0;
start();
}
void ReceiveA(bool x) {
if(state == 1) {
code = code * 2 + x;
cnt++;
if(cnt == 9) {
if(last_dist + code < dist) {
dist = last_dist + code;
state = 2;
code = 0;
cnt = 0;
} else {
send_who(u);
upd(dist, u);
state = 0;
code = 0;
cnt = 0;
if(u != (1 << 11) - 1)
start();
}
}
} else if(state == 2) {
code = code * 2 + x;
cnt++;
if(cnt == 11) {
u = code;
upd(dist, u);
state = 0;
code = 0;
cnt = 0;
start();
}
} else throw;
}
vi Answer() {
vi ans(n);
for(int i = 0; i < n; i++) {
// assert(vis[i]);
ans[i] = d[i];
}
return ans;
}
#include "Baijan.h"
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 2005;
namespace {
V<pi> G[N];
int d[N], vis[N];
int n;
int state, last_dist;
int u, dist, code, cnt;
// state
// 0: wait A
// 1:
void send_cost(int cost) {
for(int i = 8; i >= 0; i--)
SendB(cost >> i & 1);
}
void send_who(int who) {
for(int i = 10; i >= 0; i--)
SendB(who >> i & 1);
}
void upd(int dist, int u) {
if(u == (1 << 11) - 1)
return;
d[u] = dist;
vis[u] = 1;
last_dist = dist;
for(auto [v, w]:G[u]) {
if(d[u] + w < d[v]) {
d[v] = d[u] + w;
}
}
}
void start() {
dist = last_dist + (1 << 9) - 1, u = (1 << 11) - 1;
for(int i = 0; i < n; i++) if(!vis[i]) {
if(d[i] < dist) {
dist = d[i];
u = i;
}
}
}
} // namespace
void InitB(int _n, int A, vi u, vi v, vi c) {
n = _n;
for(int i = 0; i < A; i++) {
G[u[i]].EB(v[i], c[i]);
G[v[i]].EB(u[i], c[i]);
}
memset(d, 0x3f, sizeof(d[0]) * n);
memset(vis, 0, sizeof(vis[0]) * n);
d[0] = 0;
state = 0;
last_dist = 0;
code = 0;
cnt = 0;
}
void ReceiveB(bool x) {
if(state == 0) {
code = code * 2 + x;
cnt++;
if(cnt == 9) {
start();
if(last_dist + code > dist) {
int tt = dist - last_dist;
cnt = 0;
code = 0;
state = 0;
upd(dist, u);
send_cost(tt);
send_who(u);
} else {
int tt = dist - last_dist;
dist = last_dist + code;
cnt = 0;
code = 0;
state = 1;
send_cost(tt);
}
}
} else if(state == 1) {
code = code * 2 + x;
cnt++;
if(cnt == 11) {
u = code;
cnt = 0;
code = 0;
state = 0;
upd(dist, u);
}
}
}
Compilation message
Azer.cpp: In function 'void {anonymous}::upd(int, int)':
Azer.cpp:49:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
49 | for(auto [v, w]:G[u]) {
| ^
Baijan.cpp: In function 'void {anonymous}::upd(int, int)':
Baijan.cpp:44:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | for(auto [v, w]:G[u]) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
271 ms |
324 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
648 KB |
Output is correct |
2 |
Incorrect |
233 ms |
324 KB |
Wrong Answer [2] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
206 ms |
324 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
768 KB |
Output is correct |
2 |
Correct |
209 ms |
768 KB |
Output is correct |
3 |
Correct |
292 ms |
13424 KB |
Output is correct |
4 |
Correct |
148 ms |
648 KB |
Output is correct |
5 |
Correct |
301 ms |
10128 KB |
Output is correct |
6 |
Correct |
246 ms |
648 KB |
Output is correct |
7 |
Correct |
224 ms |
648 KB |
Output is correct |
8 |
Correct |
203 ms |
648 KB |
Output is correct |
9 |
Correct |
317 ms |
18048 KB |
Output is correct |
10 |
Correct |
358 ms |
18300 KB |
Output is correct |
11 |
Correct |
402 ms |
35716 KB |
Output is correct |
12 |
Correct |
372 ms |
30572 KB |
Output is correct |
13 |
Correct |
205 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
768 KB |
Output is correct |
2 |
Correct |
209 ms |
768 KB |
Output is correct |
3 |
Correct |
292 ms |
13424 KB |
Output is correct |
4 |
Correct |
148 ms |
648 KB |
Output is correct |
5 |
Correct |
301 ms |
10128 KB |
Output is correct |
6 |
Correct |
246 ms |
648 KB |
Output is correct |
7 |
Correct |
224 ms |
648 KB |
Output is correct |
8 |
Correct |
203 ms |
648 KB |
Output is correct |
9 |
Correct |
317 ms |
18048 KB |
Output is correct |
10 |
Correct |
358 ms |
18300 KB |
Output is correct |
11 |
Correct |
402 ms |
35716 KB |
Output is correct |
12 |
Correct |
372 ms |
30572 KB |
Output is correct |
13 |
Correct |
205 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
301 ms |
648 KB |
Output is correct |
16 |
Correct |
226 ms |
644 KB |
Output is correct |
17 |
Correct |
244 ms |
648 KB |
Output is correct |
18 |
Correct |
279 ms |
10096 KB |
Output is correct |
19 |
Correct |
208 ms |
720 KB |
Output is correct |
20 |
Correct |
296 ms |
10364 KB |
Output is correct |
21 |
Correct |
283 ms |
648 KB |
Output is correct |
22 |
Correct |
283 ms |
648 KB |
Output is correct |
23 |
Correct |
378 ms |
22268 KB |
Output is correct |
24 |
Correct |
423 ms |
22160 KB |
Output is correct |
25 |
Correct |
476 ms |
43504 KB |
Output is correct |
26 |
Correct |
458 ms |
36360 KB |
Output is correct |
27 |
Correct |
276 ms |
776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
768 KB |
Output is correct |
2 |
Correct |
209 ms |
768 KB |
Output is correct |
3 |
Correct |
292 ms |
13424 KB |
Output is correct |
4 |
Correct |
148 ms |
648 KB |
Output is correct |
5 |
Correct |
301 ms |
10128 KB |
Output is correct |
6 |
Correct |
246 ms |
648 KB |
Output is correct |
7 |
Correct |
224 ms |
648 KB |
Output is correct |
8 |
Correct |
203 ms |
648 KB |
Output is correct |
9 |
Correct |
317 ms |
18048 KB |
Output is correct |
10 |
Correct |
358 ms |
18300 KB |
Output is correct |
11 |
Correct |
402 ms |
35716 KB |
Output is correct |
12 |
Correct |
372 ms |
30572 KB |
Output is correct |
13 |
Correct |
205 ms |
648 KB |
Output is correct |
14 |
Correct |
2 ms |
648 KB |
Output is correct |
15 |
Correct |
301 ms |
648 KB |
Output is correct |
16 |
Correct |
226 ms |
644 KB |
Output is correct |
17 |
Correct |
244 ms |
648 KB |
Output is correct |
18 |
Correct |
279 ms |
10096 KB |
Output is correct |
19 |
Correct |
208 ms |
720 KB |
Output is correct |
20 |
Correct |
296 ms |
10364 KB |
Output is correct |
21 |
Correct |
283 ms |
648 KB |
Output is correct |
22 |
Correct |
283 ms |
648 KB |
Output is correct |
23 |
Correct |
378 ms |
22268 KB |
Output is correct |
24 |
Correct |
423 ms |
22160 KB |
Output is correct |
25 |
Correct |
476 ms |
43504 KB |
Output is correct |
26 |
Correct |
458 ms |
36360 KB |
Output is correct |
27 |
Correct |
276 ms |
776 KB |
Output is correct |
28 |
Correct |
379 ms |
648 KB |
Output is correct |
29 |
Correct |
367 ms |
656 KB |
Output is correct |
30 |
Correct |
441 ms |
24060 KB |
Output is correct |
31 |
Correct |
238 ms |
660 KB |
Output is correct |
32 |
Correct |
441 ms |
21108 KB |
Output is correct |
33 |
Correct |
356 ms |
732 KB |
Output is correct |
34 |
Correct |
339 ms |
904 KB |
Output is correct |
35 |
Correct |
347 ms |
776 KB |
Output is correct |
36 |
Correct |
407 ms |
24716 KB |
Output is correct |
37 |
Correct |
422 ms |
24708 KB |
Output is correct |
38 |
Correct |
605 ms |
48884 KB |
Output is correct |
39 |
Correct |
493 ms |
44416 KB |
Output is correct |
40 |
Correct |
289 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
271 ms |
324 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |