Submission #988315

#TimeUsernameProblemLanguageResultExecution timeMemory
988315abczzTwo Transportations (JOI19_transportations)C++14
0 / 100
391 ms51400 KiB
#include "Azer.h" #include <iostream> #include <vector> #include <queue> #include <array> #define ll long long using namespace std; namespace { vector <int> dist; vector <ll> ord; vector <array<ll, 2>> adj[2000]; bool b = 0; ll p_cost = 0, queue_sz = 0, qx = 0, qy = 0, gx, gy, resp = -1; priority_queue <array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> pq; void print(ll u, ll x) { for (int i=x-1; i>=0; --i) { SendA((bool)(u & (1LL<<i))); } } void search(ll u) { for (auto [v, x] : adj[u]) { if (dist[v] > dist[u] + x) { dist[v] = dist[u] + x; pq.push({dist[v], v}); } } } void solve() { auto u = ord.back(); ord.pop_back(); //cout << u << "*\n"; if (!u) { gx = gy = 0; while (!pq.empty()) { auto [w, u] = pq.top(); pq.pop(); if (dist[u] != w) continue; gx = w, gy = u; //cout << w << " " << u << "?\n"; //cout << p_cost << endl; print(w-p_cost, 9); print(u, 11); break; } if (!gy) { //cout << gx << " " << gy << "?\n"; print(gx, 9); print(gy, 11); } b = 1; } else b = 0; } } void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) { srand(-1); dist.resize(N); for (int i=0; i<N; ++i) { if (i) dist[i] = (ll)1e9; ord.push_back(rand() & 1); } for (int i=0; i<A; ++i) { adj[U[i]].push_back({V[i], C[i]}); adj[V[i]].push_back({U[i], C[i]}); } search(0); solve(); } void ReceiveA(bool r) { //cout << "A\n"; if (b) { if (resp == -1) { if (r) { //cout << "bitA" << " " << r << endl; dist[gy] = gx; search(gy); p_cost = gx; solve(); } else resp = 0; return; } if (queue_sz < 9) qx = 2 * qx + (ll)r; else qy = 2 * qy + (ll)r; queue_sz = (queue_sz + 1) % 20; if (queue_sz) return; qx += p_cost; dist[qy] = qx; search(qy); if (qy != gy && gy) pq.push({gx, gy}); p_cost = qx; solve(); resp = -1, qx = qy = 0; return; } if (queue_sz < 9) qx = 2 * qx + (ll)r; else qy = 2 * qy + (ll)r; queue_sz = (queue_sz + 1) % 20; if (queue_sz) return; ll x = 0, y = 0; qx += p_cost; while (!pq.empty()) { auto [w, u] = pq.top(); pq.pop(); if (dist[u] != w) continue; x = w, y = u; break; } //cout << x << " " << y << "!\n"; //cout << qx << " " << qy << "a\n"; if (!y && !qy) return; if (!y) x = 1e9; if (!qy) qx = 1e9; if (qx <= x) { dist[qy] = qx; search(qy); if (qy != y && y) pq.push({x, y}); SendA(1); p_cost = qx; } else { dist[y] = x; search(y); SendA(0); //cout << qx << " " << qy << "no\n"; print(x-p_cost, 9); print(y, 11); p_cost = x; } //cout << p_cost << endl; qx = qy = 0; solve(); } std::vector<int> Answer() { return dist; }
#include "Baijan.h" #include <vector> #include <iostream> #include <queue> #include <array> #define ll long long using namespace std; namespace { vector <int> distB; vector <ll> ordB; vector <array<ll, 2>> adjB[2000]; bool modeB = 0; ll p_costB = 0, queue_szB = 0, qxB = 0, qyB = 0, gxB, gyB, respB = -1; priority_queue <array<ll, 2>, vector<array<ll, 2>>, greater<array<ll, 2>>> pqB; void printB(ll u, ll x) { for (int i=x-1; i>=0; --i) { SendB((bool)(u & (1LL<<i))); } } void searchB(ll u) { for (auto [v, x] : adjB[u]) { if (distB[v] > distB[u] + x) { distB[v] = distB[u] + x; pqB.push({distB[v], v}); } } } void solveB() { auto u = ordB.back(); ordB.pop_back(); //cout << u << "**\n"; if (u) { gxB = gyB = 0; while (!pqB.empty()) { auto [w, u] = pqB.top(); pqB.pop(); if (distB[u] != w) continue; gxB = w, gyB = u; //cout << w << " " << u << "??\n"; //cout << p_cost << endl; printB(w-p_costB, 9); printB(u, 11); break; } if (!gyB) { //cout << gx << " " << gy << "??\n"; printB(gxB, 9); printB(gyB, 11); } modeB = 1; } else modeB = 0; } } void InitB(int N, int B, std::vector<int> S, std::vector<int> T, std::vector<int> D) { srand(-1); distB.resize(N); for (int i=0; i<N; ++i) { if (i) distB[i] = (ll)1e9; ordB.push_back(rand() & 1); } for (int i=0; i<B; ++i) { adjB[S[i]].push_back({T[i], D[i]}); adjB[T[i]].push_back({S[i], D[i]}); } searchB(0); solveB(); } void ReceiveB(bool r) { //cout << "B\n"; if (modeB) { if (respB == -1) { //cout << "bitB " << r << endl; if (r) { distB[gyB] = gxB; searchB(gyB); //cout << gx << " " << gy << "aidja\n"; p_costB = gxB; solveB(); } else respB = 0; return; } if (queue_szB < 9) qxB = 2 * qxB + (ll)r; else qyB = 2 * qyB + (ll)r; queue_szB = (queue_szB + 1) % 20; if (queue_szB) return; qxB += p_costB; distB[qyB] = qxB; if (qyB != gyB && gyB) pqB.push({gxB, gyB}); searchB(qyB); p_costB = qxB; solveB(); respB = -1, qxB = qyB = 0; return; } if (queue_szB < 9) qxB = 2 * qxB + (ll)r; else qyB = 2 * qyB + (ll)r; queue_szB = (queue_szB + 1) % 20; if (queue_szB) return; ll x = 0, y = 0; qxB += p_costB; while (!pqB.empty()) { auto [w, u] = pqB.top(); pqB.pop(); if (distB[u] != w) continue; x = w, y = u; break; } //cout << x << " " << y << "!!\n"; //cout << qx << " " << qy << "b\n"; if (!y && !qyB) return; if (!y) x = 1e9; if (!qyB) qxB = 1e9; if (qxB <= x) { distB[qyB] = qxB; searchB(qyB); if (qyB != y && y) pqB.push({x, y}); SendB(1); p_costB = qxB; } else { distB[y] = x; searchB(y); SendB(0); printB(x-p_costB, 9); printB(y, 11); p_costB = x; } //cout << p_cost << endl; qxB = qyB = 0; solveB(); }

Compilation message (stderr)

Azer.cpp: In function 'void {anonymous}::search(long long int)':
Azer.cpp:23:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for (auto [v, x] : adj[u]) {
      |               ^
Azer.cpp: In function 'void {anonymous}::solve()':
Azer.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |         auto [w, u] = pq.top();
      |              ^
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:108:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  108 |     auto [w, u] = pq.top();
      |          ^

Baijan.cpp: In function 'void {anonymous}::searchB(long long int)':
Baijan.cpp:23:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   23 |     for (auto [v, x] : adjB[u]) {
      |               ^
Baijan.cpp: In function 'void {anonymous}::solveB()':
Baijan.cpp:37:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |         auto [w, u] = pqB.top();
      |              ^
Baijan.cpp: In function 'void ReceiveB(bool)':
Baijan.cpp:109:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  109 |     auto [w, u] = pqB.top();
      |          ^
#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...