Submission #842313

# Submission time Handle Problem Language Result Execution time Memory
842313 2023-09-02T18:22:20 Z flashmt Closing Time (IOI23_closing) C++17
8 / 100
106 ms 23528 KB
#include "closing.h"
#ifdef LOCAL
#include "Debug.h"
#else
#define debug(...) 42
#endif
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;

int n;
vector<pair<int, int>> a[N];

vector<long long> bfs(int s)
{
  vector<long long> dist(n, -1);
  queue<int> q;
  dist[s] = 0;
  q.push(s);
  while (!empty(q))
  {
    int x = q.front();
    q.pop();
    for (auto [y, w] : a[x])
      if (dist[y] < 0)
      {
        dist[y] = dist[x] + w;
        q.push(y);
      }
  }
  return dist;
}

int max_score(int N, int A, int B, long long budget, vector<int> U, vector<int> V, vector<int> W)
{
  n = N;
  for (int i = 0; i < n; i++)
    a[i].clear();
  for (int i = 0; i < size(U); i++)
  {
    a[U[i]].push_back({V[i], W[i]});
    a[V[i]].push_back({U[i], W[i]});
  }

  auto distA = bfs(A);
  auto distB = bfs(B);
  auto distAB = distA[B];

  if (distAB > budget * 2)
  {
    vector<long long> allDists = distA;
    for (auto d : distB)
      allDists.push_back(d);
    sort(begin(allDists), end(allDists));
    int ans = 0;
    for (auto d : allDists)
      if (d <= budget)
      {
        ans++;
        budget -= d;
      }
    return ans;
  }

  vector<long long> intCosts, extCosts;
  for (int i = 0; i < n; i++)
  {
    auto cost = min(distA[i], distB[i]);
    if (distA[i] + distB[i] == distAB) intCosts.push_back(cost);
    else extCosts.push_back(cost);
  }

  int szInt = size(intCosts);
  sort(begin(intCosts), end(intCosts));
  vector<long long> sumIntSmall(szInt + 1);
  vector<long long> sumIntBoth(szInt + 1);
  for (int i = 0; i < szInt; i++)
  {
    sumIntSmall[i + 1] = sumIntSmall[i] + intCosts[i];
    sumIntBoth[i + 1] = sumIntBoth[i] + distAB - intCosts[i];
  }

  int szExt = size(extCosts);
  sort(begin(extCosts), end(extCosts));
  vector<long long> sumExt(szExt + 1);
  for (int i = 0; i < szExt; i++)
    sumExt[i + 1] = sumExt[i] + extCosts[i];

  debug(intCosts);
  debug(extCosts);

  int ans = 0;
  for (int i = 0; i <= szInt; i++)
  {
    long long curCost = sumIntBoth[i];
    if (curCost > budget)
      continue;

    int curAns = i * 2;
    priority_queue<pair<long long, int>> q;
    for (int j = i; j < szInt; j++)
      q.push({-intCosts[j], 1});
    for (int j = 0; j < szExt; j++)
      q.push({-extCosts[j], 0});

    while (!empty(q))
    {
      auto [cost, isInt] = q.top();
      q.pop();
      cost *= -1;
      curCost += cost;
      if (curCost > budget)
        break;
      curAns++;
      if (!isInt)
        q.push({-distAB, 1});
    }

    ans = max(ans, curAns);
  }

  return ans;
}

Compilation message

closing.cpp: In function 'int max_score(int, int, int, long long int, std::vector<int>, std::vector<int>, std::vector<int>)':
closing.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int i = 0; i < size(U); i++)
      |                   ~~^~~~~~~~~
closing.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 42
      |                    ^~
closing.cpp:89:3: note: in expansion of macro 'debug'
   89 |   debug(intCosts);
      |   ^~~~~
closing.cpp:5:20: warning: statement has no effect [-Wunused-value]
    5 | #define debug(...) 42
      |                    ^~
closing.cpp:90:3: note: in expansion of macro 'debug'
   90 |   debug(extCosts);
      |   ^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 105 ms 23528 KB Output is correct
2 Correct 106 ms 23060 KB Output is correct
3 Correct 64 ms 7584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '34', found: '24'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '34', found: '24'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '34', found: '24'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB 1st lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -