답안 #1027652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1027652 2024-07-19T08:25:57 Z 우민규(#10951) Dungeon 2 (JOI16_dungeon2) C++14
0 / 100
1 ms 856 KB
#include "dungeon2.h"

#include <bits/stdc++.h>
using namespace std;
// edge no, is back-edge?, is going back (depth decreasing)?
vector<tuple<int, bool, bool>> dfs_travel;
vector<pair<int, int>> saw;

enum DfsState {
  Unvisited = 1,
  Visiting,
  Left,
};

void dfs() {
  int back = LastRoad();
  int num_roads = NumberOfRoads();
  for (int i = 0; i < num_roads; ++i) {
    if (i + 1 == back) continue;
    dfs_travel.push_back({i, false, false});
    Move(i + 1, Visiting);

    int back2 = LastRoad();

    switch (Color()) {
      case Unvisited:
        dfs();
        dfs_travel.push_back({back2 - 1, false, true});
        break;
      case Visiting:
        dfs_travel.back() = {i, true, true};
        dfs_travel.push_back({back2 - 1, true, false});
        break;
      case Left:
        // going to already-visited child
        dfs_travel.pop_back();
        break;
    }
    Move(back2, Left);
  }
}

void Inspect(int r) {
  dfs();
  saw.assign(dfs_travel.size(), {0, 0});
  int n;
  for (int chunk = 1; chunk < 200; chunk *= 3) {
    int cur = 0;
    int travel_idx = 0;
    bool is_new_node = true;
    for (auto [edge, is_back_edge, is_going_back] : dfs_travel) {
      int color = is_new_node ? 1 + (cur / chunk) % 3 : Color();
      if (!is_back_edge && !is_going_back) {
        // going to new node, so assign
        is_new_node = true;
        cur += 1;
      } else {
        is_new_node = false;
      }

      if (is_going_back) {
        int u_color = color - 1;
        Move(edge + 1, color);
        int v_color = Color() - 1;
        saw[travel_idx].first += u_color * chunk;
        saw[travel_idx].second += v_color * chunk;
      } else {
        // depth increasing, could be back edge
        Move(edge + 1, color);
      }

      travel_idx += 1;
    }
    n = cur + 1;
  }
  vector<vector<int>> adj(n);
  for (int i = 0; i < saw.size(); ++i) {
    // is_going_back
    if (get<2>(dfs_travel[i])) {
      adj[saw[i].first].push_back(saw[i].second);
      adj[saw[i].second].push_back(saw[i].first);
    }
  }
  vector<int> answers(n);
  for (int src = 0; src < n; ++src) {
    // do bfs on src
    queue<pair<int, int>> q;
    vector<int> dist(n, INT_MAX);
    dist[src] = 0;
    q.push({0, src});
    while (!q.empty()) {
      auto [d, node] = q.front();
      q.pop();
      for (auto v : adj[node]) {
        if (dist[v] > d + 1) {
          dist[v] = d + 1;
          q.push({d + 1, v});
        }
      }
    }
    for (int i = 0; i < n; ++i) {
      assert(dist[i] != INT_MAX);
      answers[dist[i]] += 1;
    }
  }
  for (int i = 1; i <= r; ++i) {
    Answer(i, answers[i] / 2);
  }
}

#ifndef EVAL
#include "grader.cpp"
#endif

Compilation message

dungeon2.cpp: In function 'void Inspect(int)':
dungeon2.cpp:51:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for (auto [edge, is_back_edge, is_going_back] : dfs_travel) {
      |               ^
dungeon2.cpp:77:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for (int i = 0; i < saw.size(); ++i) {
      |                   ~~^~~~~~~~~~~~
dungeon2.cpp:92:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   92 |       auto [d, node] = q.front();
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 856 KB Wrong Answer [4]
2 Halted 0 ms 0 KB -