QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#618307#3047. Wind of ChangeGodzillaRE 0ms0kbC++143.2kb2024-10-06 20:49:142024-10-06 20:49:15

Judging History

你现在查看的是最新测评结果

  • [2024-10-06 20:49:15]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-06 20:49:14]
  • 提交

answer

#include <bits/stdc++.h>
#define file_in(x) (freopen(#x".in", "r", stdin))
#define file_out(x) (freopen(#x".out", "w", stdout))
#define int long long
#define ull unsigned long long
#define vi vector
#define pb push_back
#define db long double
#define pr pair <int, int>
#define mk make_pair
#define fi first
#define se second
#define lb(x) (x & (-x))

using namespace std;

char _c; bool _f; template <class T> void IN(T &x) {
  _f = x = 0; while (_c = getchar(), !isdigit(_c)) {if (_c == '-') _f = 1;}
  while (isdigit(_c)) {x = x * 10 + _c - '0', _c = getchar();} if (_f) x = -x;
}

template <class T> void _write(T x) {
  if (x < 0) return putchar('-'), _write(-x), void();
  if (x > 9) _write(x / 10);
  putchar('0' + x % 10);
}
template <class T> void write(T x) {_write(x), putchar('\n');}
template <class T> void write_s(T x) {_write(x), putchar(' ');}
template <class first, class... rest> void write(first fir, rest... res) {
  write_s(fir), write(res...);
}

#define debug(...) (_debug(#__VA_ARGS__, __VA_ARGS__))
template <class T> void _debug(const char *format, T x) {
  cerr << format << " = " << x << endl;
}
template <class first, class... rest>
void _debug(const char *format, first fir, rest... res) {
  while (*format != ',') cerr << *format++;
  cerr << " = " << fir << ',', _debug(format + 1, res...);
}

bool START;

const int N = 5e4 + 5, M = 15, inf = 1e14;

int n, K, c[N][M], mtc[N], dis[M], d[M][M], pre[M], ans, a[N];
bool vis[M];
queue <int> q;

struct heap {
  priority_queue <pr, vi <pr>, greater <pr> > q;

  void push(pr t) {q.push(t);}

  void pop(int t = 0) {
    while (!q.empty() && mtc[q.top().se] != t) q.pop();
  }

  pr top() {
    if (q.empty()) return mk(-1, -1);
    return q.top();
  }

} f[M][M], g[M];

bool END;

void spfa(int n) {
  while (!q.empty()) {
    int x = q.front(); q.pop();
    vis[x] = 0;
    for (int y = 1; y <= n; ++y)
      if (dis[x] + d[x][y] < dis[y]) {
	dis[y] = dis[x] + d[x][y], pre[y] = x;
	if (!vis[y]) vis[y] = 1, q.push(y);
      }
  }
}

signed main() {
  //仔细检查,边界,特殊情况 ! ! !
  cerr << (&END - &START) / 1024.0 / 1024.0 << endl;
  IN(n), IN(K);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= K; ++j)
      IN(c[i][j]), g[j].push(mk(c[i][j], i));
  for (int i = 1; i <= K; ++i) IN(a[i]);
  int num = n;
  while (num--) {
    for (int i = 0; i <= K; ++i) dis[i] = inf, vis[i] = pre[i] = 0;
    for (int i = 0; i <= K; ++i) for (int j = 0; j <= K; ++j) d[i][j] = inf;
    while (!q.empty()) q.pop();

    for (int i = 1; i <= K; ++i) {
      g[i].pop();
      if (g[i].top().fi != -1) dis[i] = g[i].top().fi, vis[i] = 1, q.push(i);
    }

    for (int i = 1; i <= K; ++i)
      for (int j = 1; j <= K; ++j)
	if (i != j) {
	  f[i][j].pop(i);
	  if (f[i][j].top().fi != -1)
	    d[i][j] = f[i][j].top().fi;
	}
    spfa(K);
    int p = 0; dis[0] = inf;
    for (int i = 1; i <= K; ++i) if (a[i] && dis[i] < dis[p]) p = i;
    a[p]--, ans += dis[p];
    while (p) {
      int x = pre[p], y = x ? f[x][p].top().se : g[p].top().se;
      mtc[y] = p;
      for (int i = 1; i <= K; ++i)
	if (i != p)
	  f[p][i].push(mk(c[y][i] - c[y][p], y));
      p = x;
    }
  }
  write(ans);
  return 0;
}

详细

Test #1:

score: 0
Runtime Error

input:

250000
137466 116241 624409157
188961 163586 148491970
13958 122239 46409636
186120 44010 919858866
72320 102560 92679302
158544 236582 882613876
22331 114267 646741536
210782 42861 679450428
56693 45397 898958944
71188 114724 904191407
15203 225401 210626781
31071 144225 278121829
110354 83972 4557...

output:


result: