QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561588 | #7744. Elevator | PonyHex | WA | 40ms | 7092kb | C++20 | 2.5kb | 2024-09-13 00:34:52 | 2024-09-13 00:34:52 |
Judging History
answer
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
#define double long double
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
//#define int long long
const int N = 5e5 + 50;
const int M = 2005;
const ll maxm = 1e18 + 5;
const ll mod = 998244353;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
struct node {
ll num, c, h;
}mp[N];
int cmp(node a, node b) {
if (a.h > b.h)return 1;
if (a.h == b.h && a.c > b.c)return 1;
return 0;
}
void solve()
{
//感觉就是一个小模拟
//还有就是,如果为偶数,先奇先偶无所谓
//但是如果m为奇数,应该先消耗偶数,不然奇数不能被充分利用
//除此之外似乎就没有了
queue<ll>q;
ll n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> mp[i].num >> mp[i].c >> mp[i].h;
}
sort(mp + 1, mp + 1 + n, cmp);
for (int i = 1; i <= n; i++) {
if (mp[i].c == 1)q.push(i);
}
ll ans = 0;
ll ex = 0;
ll base = mp[1].h;
for (int i = 1; i <= n; i++) {
ll num = mp[i].num, c = mp[i].c, h = mp[i].h;
base = max(base, h);
if (num * c + ex >= m) {
//先凑出一次
ans += base; base = h;
ll dis = m - ex;
if (dis % c == 1) {
if (q.size()) {
ll pos = q.front();
mp[pos].num--;
if (mp[pos].num == 0)q.pop();
num -= (dis / c);
}
}
else {
num -= dis / c;
}
//再一把一把的出
if (m % c == 1) {
while (1) {
if (q.empty()) {
ans += (base * (num * c / (m - 1)));
ex = num * c % (m - 1); break;
}
if (num == 0) {
base = 0;
ex = num * c % (m - 1); break;
}
ll pos = q.front();
ll nn = mp[pos].num, hh = mp[pos].h;
ll nnn = (num * c / (m - 1));
mp[pos].num -= min(nn, nnn);
num -= min(nn, nnn) * (m - 1) / c;
if (mp[pos].num == 0)q.pop();
}
}
else {
ex = (num * c) % m;
ans += (base * (num * c / m));
}
}
else {
base = max(base, h);
ex += (num * c);
}
if (c == 1 && q.size()) {
if (q.front() == i)q.pop();
}
//cout << ans << endl;
}
if (ex)ans += base;
cout << ans << endl;
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
std::cin >> T;
while (T--)
solve();
return 0;
}
ll ksm(ll a, ll b) {
ll base = a;
ll ans = 1;
while (b) {
if (b & 1)ans *= base;
base *= base;
b >>= 1;
}
return ans;
}
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
2 4 6 1 1 8 7 2 5 1 1 7 3 2 6 8 1200000 100000 1 100000 100000 1 12345 100000 2 100000 100000 2 12345 100000 1 100000 100000 1 12345 100000 2 100000 100000 2 12345
output:
24 100000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 40ms
memory: 7092kb
input:
5501 8 104 5 2 3 6 2 4 5 2 3 6 2 9 8 2 4 2 1 3 7 2 4 8 2 8 1 290 3 1 1 12 12 6 1 2 1 2 2 1 1 2 1 2 4 6 1 1 1 2 5 6 1 4 4 1 4 6 2 4 6 2 5 4 2 5 4 1 4 5 334 1 1 4 1 2 3 4 2 1 5 1 1 2 1 2 13 218 5 2 3 5 1 4 1 2 1 1 2 5 3 2 2 1 1 3 4 2 2 1 2 5 2 2 1 2 1 5 3 2 1 5 2 1 1 1 4 10 260 7 2 1 5 1 1 5 2 4 6 1 6...
output:
9 1 23 4 5 7 1 3 9 6 1 10 4 9 17 6 4 1 8 5 5 7 1 3 24 6 3 3 2 2 2 3 8 1 5 6 9 11 151 7 10 2 7 7 8 6 5 5 1 7 3 5 10 7 7 10 8 1 4 2 3 9 1 5 2 9 1 6 7 7 6 10 19 8 10 4 10 9 2 8 3 5 9 3 6 5 3 2 6 1 3 2 2 1 6 9 6 3 4 8 9 9 2 6 1 2 6 7 5 2 5 21 8 1 2 3 4 9 3 4 6 5 9 6 1 7 3 7 3 2 2 8 7 3 5 9 7 10 7 3 2 4 ...
result:
wrong answer 25th lines differ - expected: '23', found: '24'