Submission #532097

#TimeUsernameProblemLanguageResultExecution timeMemory
5320978e7Two Transportations (JOI19_transportations)C++17
0 / 100
435 ms780 KiB
#include "Azer.h" #include <vector> #include <iostream> using namespace std; #define ll long long #define maxn 2005 #define pii pair<int, int> #define ff first #define ss second namespace { #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif const int inf = 1LL<<28; const int wbit = 9, nbit = 12; int N; int done = 0; int dis[maxn]; bool vis[maxn]; vector<pii> adj[maxn]; vector<bool> buf; int wait = 0; //0:weight, 1:node int cur = 0, bind = 0; int uind = 0, uval = 0; void send_weight(int w) { for (int i = 0;i < wbit;i++) { SendA(w & (1<<i)); } } void send_node(int id) { for (int i = 0;i < nbit;i++) { SendA(id & (1<<i)); } } int getnum() { int ret = 0; for (int i = 0;i < buf.size();i++) { ret = ret * 2 + (buf[i] ? 1 : 0); } buf.clear(); return ret; } void get_best() { int best = inf; bind = 0; for (int j = 0;j < N;j++) { if (!vis[j] && dis[j] < best) { best = dis[j]; bind = j; } } wait = 2; pary(vis, vis + N); debug("A best", bind, best - cur); send_weight(best - cur); } } // namespace std::vector<int> Answer() { std::vector<int> ans(N); for (int k = 0; k < N; ++k) { ans[k] = dis[k]; } return ans; } void ReceiveA(bool x) { buf.push_back(x); if (wait == 0 && buf.size() == wbit) { uval = getnum(); wait = 1; } else if (wait == 1 && buf.size() == nbit){ uind = getnum(); dis[uind] = cur + uval; vis[uind] = 1; for (auto [v, e]:adj[uind]) { if (dis[uind] + e < dis[v]) { dis[v] = dis[uind] + e; } } cur += uval; if (++done >= N) Answer(); else { debug(done); get_best(); } } else { buf.clear(); if (x) { wait = 0; } else { for (auto [v, e]:adj[bind]) { if (dis[bind] + e < dis[v]) { dis[v] = dis[bind] + e; } } vis[bind] = 1; cur = dis[bind]; if (++done >= N) Answer(); else { debug(done); send_node(bind); get_best(); } } } } void InitA(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) { ::N = N; 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]}); } for (int i = 0;i < N;i++) dis[i] = inf; dis[0] = 0; get_best(); }
#include "Baijan.h" #include <vector> #include <iostream> using namespace std; #define ll long long #define maxn 2005 #define pii pair<int, int> #define ff first #define ss second namespace { #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif const int inf = 1LL<<28; const int wbit = 9, nbit = 12; int N; int done = 0; int dis[maxn]; bool vis[maxn]; vector<pii> adj[maxn]; vector<bool> buf; int wait = 0; //0:weight, 1:node int cur = 0, bind = 0; int uind = 0, uval = 0; void send_weight(int w) { for (int i = 0;i < wbit;i++) { SendB(w & (1<<i)); } } void send_node(int id) { for (int i = 0;i < nbit;i++) { SendB(id & (1<<i)); } } int getnum() { int ret = 0; for (int i = 0;i < buf.size();i++) { ret = ret * 2 + (buf[i] ? 1 : 0); } buf.clear(); return ret; } void get_best() { int best = inf; bind = 0; for (int j = 0;j < N;j++) { if (!vis[j] && dis[j] < best) { best = dis[j]; bind = j; } } debug("B best", bind, best - cur, uval); if (best - cur < uval) { for (auto [v, e]:adj[bind]) { if (dis[bind] + e < dis[v]) { dis[v] = dis[bind] + e; } } vis[bind] = 1; cur = dis[bind]; wait = 0; SendB(1); send_weight(best - cur); send_node(bind); } else { wait = 1; SendB(0); } } } // namespace void ReceiveB(bool x) { buf.push_back(x); if (wait == 0 && buf.size() == wbit) { uval = getnum(); get_best(); return; } else if (wait == 1 && buf.size() == nbit){ uind = getnum(); dis[uind] = cur + uval; vis[uind] = 1; for (auto [v, e]:adj[uind]) { if (dis[uind] + e < dis[v]) { dis[v] = dis[uind] + e; } } cur += uval; wait = 0; } } void InitB(int N, int A, std::vector<int> U, std::vector<int> V, std::vector<int> C) { ::N = N; 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]}); } for (int i = 0;i < N;i++) dis[i] = inf; dis[0] = 0; }

Compilation message (stderr)

Azer.cpp: In function 'int {anonymous}::getnum()':
Azer.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0;i < buf.size();i++) {
      |                 ~~^~~~~~~~~~~~
Azer.cpp: In function 'void {anonymous}::get_best()':
Azer.cpp:21:19: warning: statement has no effect [-Wunused-value]
   21 | #define pary(...) 0
      |                   ^
Azer.cpp:68:2: note: in expansion of macro 'pary'
   68 |  pary(vis, vis + N);
      |  ^~~~
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:69:2: note: in expansion of macro 'debug'
   69 |  debug("A best", bind, best - cur);
      |  ^~~~~
Azer.cpp: In function 'void ReceiveA(bool)':
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:100:4: note: in expansion of macro 'debug'
  100 |    debug(done);
      |    ^~~~~
Azer.cpp:20:20: warning: statement has no effect [-Wunused-value]
   20 | #define debug(...) 0
      |                    ^
Azer.cpp:117:5: note: in expansion of macro 'debug'
  117 |     debug(done);
      |     ^~~~~

Baijan.cpp: In function 'int {anonymous}::getnum()':
Baijan.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0;i < buf.size();i++) {
      |                 ~~^~~~~~~~~~~~
Baijan.cpp: In function 'void {anonymous}::get_best()':
Baijan.cpp:21:20: warning: statement has no effect [-Wunused-value]
   21 | #define debug(...) 0
      |                    ^
Baijan.cpp:68:2: note: in expansion of macro 'debug'
   68 |  debug("B best", bind, best - cur, uval);
      |  ^~~~~
Baijan.cpp: At global scope:
Baijan.cpp:27:5: warning: '{anonymous}::done' defined but not used [-Wunused-variable]
   27 | int done = 0;
      |     ^~~~
#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...