QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768186#9528. New Energy VehicledodolaWA 258ms32140kbC++172.8kb2024-11-21 01:44:152024-11-21 01:44:15

Judging History

This is the latest submission verdict.

  • [2024-11-21 01:44:15]
  • Judged
  • Verdict: WA
  • Time: 258ms
  • Memory: 32140kb
  • [2024-11-21 01:44:15]
  • Submitted

answer

#include <bits/stdc++.h>

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;

ll a[maxn], b[maxn], x[maxn], t[maxn];

void solve() {
  ll n, m, ans = 0ll;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = a[i];
    ans += a[i];
  }

  map<ll, ll> dic;
  map<ll, set<ll>> mp;
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> t[i];
    dic[x[i]] = t[i]; // 位置x[i]的可以给t[i]充电
    mp[t[i]].insert(x[i]);
  }

  // if (x[1] > ans) {
  //   cout << ans << '\n';
  //   return;
  // }

  set<ll> st;
  for (int i = 1; i <= n; i++) {
    if (mp.count(i) && !mp[i].empty()) {
      st.insert(*mp[i].begin());
    }
  }

  ll sum = ans;
  for (int i = 1; i <= m; i++) {
    auto pos = *st.begin();                  // 下一个油站的位置
    ll dis = x[i] - x[i - 1], ti = dic[pos]; // 需要的油量和下一可用油站的油类型
    if (sum < dis) {
      break;
    }
    set<ll> nst;
    while (dis && !st.empty()) {
      if (dis < b[ti]) {
        b[ti] -= dis;
        dis = 0;
      } else {
        // 用完t的油,并使用下一个油箱
        dis -= b[ti];
        b[ti] = 0;
        st.erase(pos);
        mp[ti].erase(pos);
        if (!mp[ti].empty()) {
          nst.insert(*mp[ti].begin());
        }
        if (!st.empty()) {
          pos = *st.begin();
          ti = dic[pos];
        }
      }
    }

    // 删去浪费的部分
    if (!st.empty() && *st.begin() == x[i]) {
      pos = *st.begin(), ti = dic[pos];
      st.erase(pos);
      mp[ti].erase(pos);
      b[ti] = 0ll;
      if (!mp[ti].empty()) {
        nst.insert(*mp[ti].begin());
      }
    }


    if (dis) {
      // 使用最初的油填补亏空
      if (sum >= dis) {
        sum -= dis;
        dis = 0;
      }
    }
    if (dis) {
      // 回退到不借用其后的资源的状态
      ll tsum = 0ll;
      while (!st.empty()) {
        pos = *st.begin();
        ti = dic[pos];
        tsum += a[ti] - b[ti];
        st.erase(st.begin());
      }
      ans = x[i] - dis - tsum;
      break;
    }
    
    while (!nst.empty()) {
      st.insert(*nst.begin());
      ti = dic[*nst.begin()];
      b[ti] = a[ti];
      nst.erase(nst.begin());
    }
    
    ans = x[i] + sum;
  }

  cout << ans << '\n';
}

/*
1
3 5
3 3 3
8 1
10 2
11 1
13 2
16 3

23

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

12
9

1
2 3
2 2
5 1
6 2
9 1

4
*/

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: 1ms
memory: 9664kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 9700kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
11
999999999
2000000000

result:

ok 6 lines

Test #3:

score: -100
Wrong Answer
time: 258ms
memory: 32140kb

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1543020
1578939
1526016
1527381
1547404
1564631
1051729
1548178
1114655
1072438

result:

wrong answer 9th lines differ - expected: '1114634', found: '1114655'