답안 #741409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741409 2023-05-14T03:57:39 Z vjudge1 자매 도시 (APIO20_swap) C++17
0 / 100
2000 ms 12512 KB
#include "swap.h"

#include <cassert>
#include <cstdio>

#include <string>
#include <vector>

/////////////////////////////////////////////////////

#include "swap.h"

#include <bits/stdc++.h>
using namespace std;

template<typename T> int SIZE(T (&t)){ return t.size(); } template<typename T, size_t N> int SIZE(T (&t)[N]){ return N; } string to_string(char t){ return "'" + string({t}) + "'"; } string to_string(bool t){ return t ? "true" : "false"; } string to_string(const string &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += t[i]; } return '"' + ret + '"'; } string to_string(const char* t){ string ret(t); return to_string(ret); } template<size_t N> string to_string(const bitset<N> &t, int x1=0, int x2=1e9){ string ret = ""; for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){ ret += t[i] + '0'; } return to_string(ret); } template<typename T, typename... Coords> string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C); template<typename T, typename S> string to_string(const pair<T, S> &t){ return "(" + to_string(t.first) + ", " + to_string(t.second) + ")"; } template<typename T, typename... Coords> string to_string(const T (&t), int x1, int x2, Coords... C){ string ret = "["; x1 = min(x1, SIZE(t)); auto e = begin(t); advance(e,x1); for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){ ret += to_string(*e, C...) + (i != _i ? ", " : ""); e = next(e); } return ret + "]"; } template<int Index, typename... Ts> struct print_tuple{ string operator() (const tuple<Ts...>& t) { string ret = print_tuple<Index - 1, Ts...>{}(t); ret += (Index ? ", " : ""); return ret + to_string(get<Index>(t)); } }; template<typename... Ts> struct print_tuple<0, Ts...> { string operator() (const tuple<Ts...>& t) { return to_string(get<0>(t)); } }; template<typename... Ts> string to_string(const tuple<Ts...>& t) { const auto Size = tuple_size<tuple<Ts...>>::value; return print_tuple<Size - 1, Ts...>{}(t); } void dbgr(){;} template<typename Heads, typename... Tails> void dbgr(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgr(T...); } void dbgs(){;} template<typename Heads, typename... Tails> void dbgs(Heads H, Tails... T){ cout << H << " "; dbgs(T...); } 
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);

const int N = 1e5 + 5;
const int M = 2e5 + 5;
const int MAXA = 1e9 + 7;
int n, m;
array<int, 3> edge[M];
vector <int> a[N];
int ma = 0;
bool vis[N];

void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
  n = N; m = M;
  for(int i = 0; i < m; ++i){
    edge[i] = {U[i], V[i], W[i]};
    ma = max(ma, W[i]);
    //a[U[i]].push_back({V[i], W[i]});
    //a[V[i]].push_back({U[i], W[i]});
  }
}

void bfs(vector <int> &d, int u, int ban = -1){
  queue<int> q;
  q.push(u);
  while (!q.empty()){
    int u = q.front(); q.pop();
    for(int i : a[u]){
      if (i == ban) continue;
      if (d[i] == MAXA){
        d[i] = d[u] + 1;
        q.push(i);
      }
    }
  }
}

bool f(int mid, int X, int Y){
  for(int i = 0; i < n; ++i) a[i].clear();
  for(int i = 0; i < m; ++i){
    if (edge[i][2] <= mid) {
      a[edge[i][0]].push_back(edge[i][1]);
      a[edge[i][1]].push_back(edge[i][0]);
    }
  }

  vector <int> d(n, MAXA);
  d[X] = 0; bfs(d, X);

  vector <int> dx(n, MAXA), dy(n, MAXA);
  dx[X] = 0; bfs(dx, X, Y);
  dy[Y] = 0; bfs(dy, Y, X);

  //dbg(dx, 0, n - 1);
  //dbg(dy, 0, n - 1);

  int disxy = d[Y];
  if (disxy >= MAXA) return false; 

  int ct = 0;
  for(int i = 0; i < n; ++i){
    if (dx[i] == MAXA || dy[i] == MAXA) continue;
    ++ct;
  }

  return (ct > disxy - 1);
}

int getMinimumFuelCapacity(int X, int Y) {
  int l = 0, r = MAXA;
  while (l + 1 < r){
    int mid = (l + r) >> 1;
    if (f(mid, X, Y)) r = mid;
    else l = mid;
  }
  if (r == MAXA) r = -1;

  return r;
}

///////////////////////////////////////////////////////
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2568 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 7 ms 2644 KB Output is correct
6 Correct 8 ms 2644 KB Output is correct
7 Correct 10 ms 2644 KB Output is correct
8 Correct 11 ms 2644 KB Output is correct
9 Correct 548 ms 8604 KB Output is correct
10 Correct 1307 ms 10032 KB Output is correct
11 Correct 1965 ms 9912 KB Output is correct
12 Correct 1886 ms 10220 KB Output is correct
13 Execution timed out 2048 ms 10012 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2568 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Execution timed out 2056 ms 12512 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2568 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 7 ms 2644 KB Output is correct
6 Correct 8 ms 2644 KB Output is correct
7 Correct 10 ms 2644 KB Output is correct
8 Correct 11 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 7 ms 2644 KB Output is correct
11 Correct 11 ms 2644 KB Output is correct
12 Correct 11 ms 2644 KB Output is correct
13 Correct 9 ms 2760 KB Output is correct
14 Correct 9 ms 2744 KB Output is correct
15 Incorrect 9 ms 2644 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2568 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 7 ms 2644 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 10 ms 2644 KB Output is correct
9 Correct 11 ms 2644 KB Output is correct
10 Correct 548 ms 8604 KB Output is correct
11 Correct 1307 ms 10032 KB Output is correct
12 Correct 1965 ms 9912 KB Output is correct
13 Correct 1886 ms 10220 KB Output is correct
14 Execution timed out 2048 ms 10012 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2568 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 4 ms 2644 KB Output is correct
5 Correct 7 ms 2644 KB Output is correct
6 Correct 8 ms 2644 KB Output is correct
7 Correct 10 ms 2644 KB Output is correct
8 Correct 11 ms 2644 KB Output is correct
9 Correct 548 ms 8604 KB Output is correct
10 Correct 1307 ms 10032 KB Output is correct
11 Correct 1965 ms 9912 KB Output is correct
12 Correct 1886 ms 10220 KB Output is correct
13 Execution timed out 2048 ms 10012 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2568 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 4 ms 2644 KB Output is correct
6 Correct 7 ms 2644 KB Output is correct
7 Correct 8 ms 2644 KB Output is correct
8 Correct 10 ms 2644 KB Output is correct
9 Correct 11 ms 2644 KB Output is correct
10 Correct 548 ms 8604 KB Output is correct
11 Correct 1307 ms 10032 KB Output is correct
12 Correct 1965 ms 9912 KB Output is correct
13 Correct 1886 ms 10220 KB Output is correct
14 Execution timed out 2048 ms 10012 KB Time limit exceeded
15 Halted 0 ms 0 KB -