답안 #1007296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007296 2024-06-24T15:00:16 Z NeroZein 봉쇄 시간 (IOI23_closing) C++17
9 / 100
1000 ms 1390528 KB
#include "closing.h"
#include <bits/stdc++.h>

using namespace std; 

const int N = 3003;
const long long INF = 1e18 + 18; 

using pli = pair<long long, int>; 

int n, x, y;
long long k; 
long long dist[2][N];
long long dp[N][N * 2][6]; 
vector<pair<int, int>> g[N];
 
void dijkstra(int ver, int src) {
  for (int i = 0; i < n; ++i) {
    dist[ver][i] = INF;
  }
  dist[ver][src] = 0;
  priority_queue<pli, vector<pli>, greater<pli>> pq; 
  pq.emplace(0, src); 
  while (!pq.empty()) {
    auto [c, v] = pq.top();
    pq.pop();
    if (c != dist[ver][v]) {
      continue; 
    }
    for (auto [u, w] : g[v]) {
      if (c + w < dist[ver][u]) {
        dist[ver][u] = c + w; 
        pq.emplace(dist[ver][u], u); 
      }
    }
  }
}

void init() {
  for (int i = 0; i < n; ++i) {
    g[i].clear();
  }
}

int max_score(int N_, int X_, int Y_, long long K_, vector<int> U, vector<int> V, vector<int> W) {
  n = N_, x = X_, y = Y_, k = K_; 
  for (int i = 0; i < n - 1; ++i) {
    g[U[i]].emplace_back(V[i], W[i]);
    g[V[i]].emplace_back(U[i], W[i]);
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N * 2; ++j) {
      for (int l = 0; l < 6; ++l) {
        dp[i][j][l] = INF;
      }
    }
  }
  dijkstra(0, x);
  dijkstra(1, y);
  vector<int> ord(n);
  iota(ord.begin(), ord.end(), 0);
  sort(ord.begin(), ord.end(), [&](int i, int j) {
    return min(dist[0][i], dist[1][i]) < min(dist[0][j], dist[1][j]);
  });
  int tmp = 0, sum = 0; 
  for (int i = 0; i < n; ++i) {
    if (sum + min(dist[0][ord[i]], dist[1][ord[i]]) <= k) {
      sum += min(dist[0][ord[i]], dist[1][ord[i]]);
      tmp++; 
    }
  }
  dp[0][0][0] = 0;
  for (int i = 0; i < n; ++i) {
    for (int curans = 0; curans < n * 2; ++curans) {
      for (int f = 0; f < 5; ++f) {//0 nothing, 1 x, 2 xy, 3 y, 4 nothing
        dp[i][curans][f + 1] = min(dp[i][curans][f + 1], dp[i][curans][f]);
        if (i == x && f != 1 && f != 2) continue;
        if (i == y && f != 2 && f != 3) continue; 
        if (f == 2) {
          dp[i + 1][curans + 2][f] = min(dp[i + 1][curans + 2][f], dp[i][curans][f] + max(dist[0][i], dist[1][i]));
        } else if (f == 0 || f == 4) {
          dp[i + 1][curans][f] = min(dp[i + 1][curans][f], dp[i][curans][f]);
        } else {
          dp[i + 1][curans + 1][f] = min(dp[i + 1][curans + 1][f], dp[i][curans][f] + dist[f / 2][i]);
        }
      }
    }
  }
  int ans = 0; 
  for (int curans = 0; curans <= 2 * n; ++curans) {
    for (int j = 0; j <= 4; ++j) {
      if (dp[n][curans][j] <= k) {
        ans = max(ans, curans);
      }      
    }
  }
  ans = max(ans, tmp); 
  init();
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 672 ms 1390528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 847440 KB Output is correct
2 Correct 267 ms 847440 KB Output is correct
3 Correct 280 ms 847440 KB Output is correct
4 Correct 278 ms 847444 KB Output is correct
5 Correct 282 ms 847440 KB Output is correct
6 Correct 302 ms 847420 KB Output is correct
7 Correct 286 ms 847404 KB Output is correct
8 Correct 278 ms 847384 KB Output is correct
9 Correct 275 ms 847536 KB Output is correct
10 Correct 269 ms 847444 KB Output is correct
11 Correct 279 ms 847440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 847440 KB Output is correct
2 Correct 267 ms 847440 KB Output is correct
3 Correct 280 ms 847440 KB Output is correct
4 Correct 278 ms 847444 KB Output is correct
5 Correct 282 ms 847440 KB Output is correct
6 Correct 302 ms 847420 KB Output is correct
7 Correct 286 ms 847404 KB Output is correct
8 Correct 278 ms 847384 KB Output is correct
9 Correct 275 ms 847536 KB Output is correct
10 Correct 269 ms 847444 KB Output is correct
11 Correct 279 ms 847440 KB Output is correct
12 Correct 288 ms 847372 KB Output is correct
13 Correct 290 ms 847544 KB Output is correct
14 Correct 290 ms 847444 KB Output is correct
15 Correct 288 ms 847448 KB Output is correct
16 Correct 289 ms 847424 KB Output is correct
17 Correct 299 ms 847576 KB Output is correct
18 Execution timed out 1054 ms 847516 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 265 ms 847440 KB Output is correct
2 Correct 267 ms 847440 KB Output is correct
3 Correct 280 ms 847440 KB Output is correct
4 Correct 278 ms 847444 KB Output is correct
5 Correct 282 ms 847440 KB Output is correct
6 Correct 302 ms 847420 KB Output is correct
7 Correct 286 ms 847404 KB Output is correct
8 Correct 278 ms 847384 KB Output is correct
9 Correct 275 ms 847536 KB Output is correct
10 Correct 269 ms 847444 KB Output is correct
11 Correct 279 ms 847440 KB Output is correct
12 Correct 288 ms 847372 KB Output is correct
13 Correct 290 ms 847544 KB Output is correct
14 Correct 290 ms 847444 KB Output is correct
15 Correct 288 ms 847448 KB Output is correct
16 Correct 289 ms 847424 KB Output is correct
17 Correct 299 ms 847576 KB Output is correct
18 Execution timed out 1054 ms 847516 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 320 ms 847740 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -