QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788305#9730. Elevator IIshinonomezhouWA 217ms3768kbC++142.8kb2024-11-27 16:29:362024-11-27 16:29:36

Judging History

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

  • [2024-11-27 16:29:36]
  • 评测
  • 测评结果:WA
  • 用时:217ms
  • 内存:3768kb
  • [2024-11-27 16:29:36]
  • 提交

answer

#include <bits/stdc++.h>
#include <vector>

// #define x first
// #define y second

using namespace std;

typedef double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

const int maxn = 2e6 + 50;
const ll inf = 0x3f3f3f3f3f3f;
const vector<pll> dxy = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

ll n, f;

void solve() {
  cin >> n >> f;
  vector<pll> v;
  map<pll, vector<ll>> mp;
  for (ll i = 1; i <= n; i++) {
    ll l, r;
    cin >> l >> r;
    v.push_back({l, r});
    mp[{l, r}].push_back(i);
  }

  sort(v.begin(), v.end());

  vector<vector<ll>> q;
  multiset<pll, greater<>> st;

  for (ll i = 0; i < (ll)v.size(); i++) {
    auto [l, r] = v[i];
    if (q.empty()) {
      vector<ll> w;
      w.push_back(i);
      q.push_back(w);
      st.insert({r, q.size() - 1});
    } else {
      // 第一个大于等于
      auto d = lower_bound(
          st.begin(), st.end(), make_pair(l, 0), [&](pll p1, pll p2) {
            return tie(p1.first, p1.second) > tie(p2.first, p2.second);
          });
      if (d != st.end()) {
        st.erase(d);
        ll p = d->second;
        q[p].push_back(i);
        st.insert({r, p});
      } else {
        vector<ll> w;
        w.push_back(i);
        q.push_back(w);
        st.insert({r, q.size() - 1});
      }
    }
  }

  sort(q.begin(), q.end(), [&](vector<ll> &v1, vector<ll> &v2) {
    return v[v1.back()].second > v[v2.back()].second;
  });

  vector<ll> ans;

  bool flag = false;
  for (ll qi = 0; qi < (ll)q.size(); qi++) {
    auto vi = q[qi];
    for (ll i = 0; i < (ll)vi.size(); i++) {
      ll p = vi[i];
      if (v[p].first >= f &&
          (i == 0 || (i - 1 >= 0 && v[vi[i - 1]].second <= f))) {
        for (ll j = i; j < (ll)vi.size(); j++) {
          ans.push_back(vi[j]);
        }
        for (ll j = 0; j < i; j++) {
          ans.push_back(vi[j]);
        }
        flag = true;
        q.erase(q.begin() + qi);
        break;
      }
    }
    if (flag)
      break;
  }

  for (auto i : q) {
    for (auto j : i) {
      ans.push_back(j);
    }
  }

  ll tot = 0ll;
  for (ll i = 0; i < (ll)ans.size(); i++) {
    ll p = ans[i];
    if (i == 0) {
      tot = max(v[p].first - f, 0ll) + v[p].second - v[p].first;
    } else {
      tot += max(v[p].first - v[ans[i - 1]].second, 0ll) + v[p].second -
             v[p].first;
    }
  }
  cout << tot << '\n';
  for (auto i : ans) {
    cout << mp[v[i]].front() << ' ';
    mp[v[i]].erase(mp[v[i]].begin());
  }
  cout << '\n';
}

void init() {
  // init_primes();
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  int _t = 1;
  cin >> _t;
  cin.get();
  while (_t--)
    solve();

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3536kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
3 2 1 4 
5
2 1 

result:

ok ok 2 cases (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 217ms
memory: 3768kb

input:

6100
19 52
51 98
2 83
40 58
96 99
39 55
72 94
15 17
4 15
48 99
2 99
77 78
35 77
44 62
79 81
30 31
1 48
48 76
68 99
60 66
6 19
44 53
64 92
17 28
67 98
9 99
40 65
16 27
99 100
15 56
4 6
24 97
84 96
47 49
37 38
77 79
13 40
13 92
71 100
47 93
90 91
72 81
15 48
32 71
19 17
95 99
10 23
18 100
90 93
52 92
...

output:

583
10 3 19 18 13 6 4 9 1 2 16 17 11 14 7 15 12 8 5 
244
1 2 5 3 6 4 
485
16 14 5 2 11 4 1 7 12 10 3 9 6 8 13 15 
773
3 7 4 1 10 15 8 6 11 17 5 19 16 13 12 18 2 14 9 
313
2 5 8 6 7 15 1 10 12 4 14 13 3 9 11 
481
1 18 19 6 5 7 11 3 15 2 10 8 13 9 17 12 4 16 20 14 
123
4 1 2 3 
228
2 8 5 7 3 10 9 6 1 ...

result:

wrong answer Participant's cost is 583, which is worse than jury's cost 524 (test case 1)