제출 #123569

#제출 시각아이디문제언어결과실행 시간메모리
123569songcTwo Transportations (JOI19_transportations)C++14
0 / 100
14 ms1760 KiB
#include <bits/stdc++.h> #include "Azer.h" using namespace std; typedef long long LL; typedef pair<int, int> pii; namespace{ int N, M, cnt; vector<pii> adj[2020]; vector<int> ans; int L, num, mode, d; pii T; bool chk[2020]; priority_queue<pii, vector<pii>, greater<pii>> PQ; void SendNum(int x, int b){for (int i=0; i<b; i++) SendA(x & (1<<i));} } void InitA(int n, int A, vector<int> U, vector<int> V, vector<int> C){ N = n, M = A; ans.resize(N); for (int i=0; i<A; i++){ adj[U[i]].push_back(pii(V[i], C[i])); adj[V[i]].push_back(pii(U[i], C[i])); } PQ.push(pii(0, 0)); } void ReceiveA(bool x){ start: if (mode == 0){ if (x) mode = 1; else{ mode = -1; d = 0; return; } } if (mode == 1){ while (1){ if (PQ.empty()) { T = pii(505+L, 0); break; } else{ T = PQ.top(); PQ.pop(); if (chk[T.second]) continue; break; } } SendNum(T.first - L, 9); mode = 2; return; } if (mode == 2){ if (x) { SendNum(T.second, 11); mode = 5; } else{ PQ.push(T); T.first = T.second = 0; mode = 3; return; } } if (mode == 3){ if (x) T.second |= (1<<num); num++; if (num == 11){ num = 0; mode = 4; return; } } if (mode == 4){ if (x) T.first |= (1<<num); num++; if (num == 9){ T.first += L; num = 0; mode = 5; } } if (mode == 5){ ans[T.second] = T.first; chk[T.second] = true; cnt++, L = T.first; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); if (cnt == N) return; if (rand()&1){ mode = 1; SendA(false); goto start; } else { SendA(true); d = 0; mode = -1; return; } } if (mode == -1){ if (x) d |= 1 << num; num++; if (num == 9) num = 0, mode = -2; } if (mode == -2){ while (1){ if (PQ.empty()){ T.first = L+505; break; } else{ T = PQ.top(); PQ.pop(); if (chk[T.second]) continue; break; } } if (T.first-L >= d){ SendA(true); PQ.push(T); T.second = 0; T.first = d + L; mode = -3; return; } else{ ans[T.second] = T.first; chk[T.second] = true; cnt++; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); mode = 0; SendA(false); SendNum(T.second, 11); SendNum(T.first - L, 9); L = T.first; return; } } if (mode == -3){ if (x) T.second |= (1<<num); num++; if (num == 9) num = 0, mode=-4; } if (mode == -4){ ans[T.second] = T.first; chk[T.second] = true; cnt++; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); mode = 0; L = T.first; return; } } vector<int> Answer() {return ans;}
#include <bits/stdc++.h> #include "Baijan.h" using namespace std; typedef long long LL; typedef pair<int, int> pii; namespace{ int N, M, cnt; vector<pii> adj[2020]; int L, num, mode=-1, d; pii T; bool chk[2020]; priority_queue<pii, vector<pii>, greater<pii>> PQ; void SendNum(int x, int b){for (int i=0; i<b; i++) SendB(x & (1<<i));} } void InitB(int n, int A, vector<int> U, vector<int> V, vector<int> C){ N = n, M = A; for (int i=0; i<A; i++){ adj[U[i]].push_back(pii(V[i], C[i])); adj[V[i]].push_back(pii(U[i], C[i])); } PQ.push(pii(0, 0)); SendB(true); } void ReceiveB(bool x){ start: if (mode == 0){ if (x) mode = 1; else{ mode = -1; d = 0; return; } } if (mode == 1){ while (1){ if (PQ.empty()) { T = pii(505+L, 0); break; } else{ T = PQ.top(); PQ.pop(); if (chk[T.second]) continue; break; } } SendNum(T.first - L, 9); mode = 2; return; } if (mode == 2){ if (x) { SendNum(T.second, 11); mode = 5; } else{ PQ.push(T); T.first = T.second = 0; mode = 3; return; } } if (mode == 3){ if (x) T.second |= (1<<num); num++; if (num == 11){ num = 0; mode = 4; return; } } if (mode == 4){ if (x) T.first |= (1<<num); num++; if (num == 9){ T.first += L; num = 0; mode = 5; } } if (mode == 5){ chk[T.second] = true; cnt++, L = T.first; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); if (cnt == N) return; if (rand()&1){ mode = 1; SendB(false); goto start; } else { SendB(true); d = 0; mode = -1; return; } } if (mode == -1){ if (x) d |= 1 << num; num++; if (num == 9) num = 0, mode = -2; } if (mode == -2){ while (1){ if (PQ.empty()){ T.first = L+505; break; } else{ T = PQ.top(); PQ.pop(); if (chk[T.second]) continue; break; } } if (T.first-L >= d){ SendB(true); PQ.push(T); T.second = 0; T.first = d + L; mode = -3; return; } else{ chk[T.second] = true; cnt++; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); mode = 0; SendB(false); SendNum(T.second, 11); SendNum(T.first - L, 9); L = T.first; return; } } if (mode == -3){ if (x) T.second |= (1<<num); num++; if (num == 11) num = 0, mode=-4; } if (mode == -4){ chk[T.second] = true; cnt++; for (pii v : adj[T.second]) PQ.push(pii(T.first+v.second, v.first)); mode = 0; L = T.first; return; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...