QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#757126 | #9552. The Chariot | ucup-team3584# | WA | 42ms | 3692kb | C++23 | 15.8kb | 2024-11-17 00:30:38 | 2024-11-17 00:30:38 |
Judging History
answer
#include <string.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> using vvvc = vector<vector<vector<T>>>;
template<class T> using pq = priority_queue<T,vector<T>,greater<T>>;
template <class T, class S> inline bool chmax(T &a, const S &b) { return (a < b ? a = b, 1 : 0); }
template <class T, class S> inline bool chmin(T &a, const S &b) { return (a > b ? a = b, 1 : 0); }
int dx4[] = {1,0,-1,0};
int dy4[] = {0,1,0,-1};
#define overload5(a, b, c, d, e, name, ...) name
#define overload4(a, b, c, d, name, ...) name
#define REP0(n) for(ll jidlsjf = 0; jidlsjf < n; ++jidlsjf)
#define REP1(i, n) for(ll i = 0; i < (n); ++i)
#define REP2(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, REP3, REP2, REP1, REP0)(__VA_ARGS__)
#define per0(n) for(int jidlsjf = 0; jidlsjf < (n); ++jidlsjf)
#define per1(i, n) for(ll i = (n)-1; i >= 0; --i)
#define per2(i, a, b) for(ll i = (a)-1; i >= b; --i)
#define per3(i, a, b, c) for(ll i = (a)-1; i >= (b); i -= (c))
#define per(...) overload4(__VA_ARGS__, per3, per2, per1, per0)(__VA_ARGS__)
#define setbits(j, n) for(ll iiiii = (n), j = lowbit(iiiii); iiiii; iiiii ^= 1 << j, j = lowbit(iiiii))
#define perm(v) for(bool permrepflag = true; (permrepflag ? exchange(permrepflag, false) : next_permutation(all(v)));)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define ppf pop_front
#define drop(s) cout << #s << endl, exit(0)
#define si(c) (int)(c).size()
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define lbg(c, x) distance((c).begin(), lower_bound(all(c), (x), greater{}))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define ubg(c, x) distance((c).begin(), upper_bound(all(c), (x), greater{}))
#define rng(v, l, r) v.begin() + (l), v.begin() + (r)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define SORT(v) sort(all(v))
#define REV(v) reverse(all(v))
#define UNIQUE(x) SORT(x), x.erase(unique(all(x)), x.end())
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
namespace rklib {
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin_non_negative(T &a, const T &b) {
if (a < 0 || a > b) {
a = b;
return true;
}
return false;
}
template <class T>
T div_floor(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
if (b < 0) a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
} // namespace rklib
#include <string>
#include <type_traits>
#include <vector>
namespace rklib {
struct BigInt {
public:
BigInt() : BigInt(0) {}
template <typename T, std::enable_if_t<std::is_integral<T>::value,
std::nullptr_t> = nullptr>
BigInt(T x) : BigInt(std::vector<T>(1, x)) {}
template <typename T, std::enable_if_t<std::is_integral<T>::value,
std::nullptr_t> = nullptr>
BigInt(std::vector<T> a) {
while (a.size() >= 2 && a.back() == 0) a.pop_back();
if (a.size() == 1 && a[0] == 0) {
sgn = 0;
v = {0};
return;
}
sgn = (a.back() > 0 ? 1 : -1);
if (sgn < 0) {
std::transform(a.begin(), a.end(), a.begin(),
[](T x) { return -x; });
}
v = normalize(a);
}
BigInt(std::string s) : sgn(1) {
if (s[0] == '-') {
s.erase(s.begin());
sgn = -1;
}
if (s == "0") {
sgn = 0;
v = {0};
return;
}
for (int r = int(s.size()), l = std::max(0, r - log10_base); r > 0;
r = l, l = std::max(0, r - log10_base)) {
int tmp = 0;
for (int i = l; i < r; ++i) {
tmp = tmp * 10 + (s[i] - '0');
}
v.push_back(tmp);
}
}
BigInt& operator+=(const BigInt& rhs) {
int r_sgn = rhs.sgn;
if (r_sgn == 0) return *this;
if (sgn == 0) return *this = rhs;
if (v.size() < rhs.v.size()) v.resize(rhs.v.size(), 0);
for (size_t i = 0; i < rhs.v.size(); i++) {
if (sgn == r_sgn)
v[i] += rhs.v[i];
else
v[i] -= rhs.v[i];
}
normalize();
return *this;
}
BigInt& operator-=(const BigInt& rhs) {
int r_sgn = rhs.sgn;
if (r_sgn == 0) return *this;
if (sgn == 0) return *this = -rhs;
if (v.size() < rhs.v.size()) v.resize(rhs.v.size(), 0);
for (size_t i = 0; i < rhs.v.size(); i++) {
if (sgn == r_sgn)
v[i] -= rhs.v[i];
else
v[i] += rhs.v[i];
}
normalize();
return *this;
}
BigInt& operator*=(const BigInt& rhs) {
int r_sgn = rhs.sgn;
if (sgn == 0) return *this;
if (r_sgn == 0) return *this = rhs;
int res_sgn = sgn * r_sgn;
if (int(std::min(v.size(), rhs.v.size())) <= naive_mul_threshold) {
v = multiply_naive(v, rhs.v);
} else {
std::vector<long long> a(v.size()), b(rhs.v.size());
for (size_t i = 0; i < a.size(); i++) {
a[i] = (long long)v[i];
}
for (size_t i = 0; i < b.size(); i++) {
b[i] = (long long)rhs.v[i];
}
int sz = 1;
while (sz < int(a.size()) || sz < int(b.size())) sz *= 2;
a.resize(sz, 0);
b.resize(sz, 0);
this->v = normalize(multiply_karatsuba(a, b));
}
this->sgn = res_sgn;
return *this;
}
BigInt& operator/=(const BigInt& rhs) {
int r_sgn = rhs.sgn;
assert(r_sgn != 0);
if (sgn == 0) return *this;
if (rhs == 1 || rhs == -1) {
sgn *= r_sgn;
return *this;
}
int res_sgn = sgn * r_sgn;
(*this) = divide_newton_raphson(*this, rhs);
this->sgn = (this->v.back() == 0 ? 0 : res_sgn);
return *this;
}
BigInt& operator%=(const BigInt& rhs) {
assert(rhs.sgn != 0);
return *this = (*this) - (*this) / rhs * rhs;
}
friend BigInt operator+(const BigInt& lhs, const BigInt& rhs) {
return BigInt(lhs) += rhs;
}
friend BigInt operator-(const BigInt& lhs, const BigInt& rhs) {
return BigInt(lhs) -= rhs;
}
friend BigInt operator*(const BigInt& lhs, const BigInt& rhs) {
return BigInt(lhs) *= rhs;
}
friend BigInt operator/(const BigInt& lhs, const BigInt& rhs) {
return BigInt(lhs) /= rhs;
}
friend BigInt operator%(const BigInt& lhs, const BigInt& rhs) {
return BigInt(lhs) %= rhs;
}
BigInt operator+() const { return *this; }
BigInt operator-() const { return {-sgn, v}; }
BigInt& operator++() { return *this += 1; }
BigInt& operator--() { return *this -= 1; }
friend bool operator==(const BigInt& lhs, const BigInt& rhs) {
if (lhs.sgn != rhs.sgn || lhs.v.size() != rhs.v.size()) return false;
for (size_t i = 0; i < lhs.v.size(); i++) {
if (lhs.v[i] != rhs.v[i]) return false;
}
return true;
}
friend bool operator!=(const BigInt& lhs, const BigInt& rhs) {
return !(lhs == rhs);
}
friend bool operator<(const BigInt& lhs, const BigInt& rhs) {
int l_sgn = lhs.sgn, r_sgn = rhs.sgn;
if (l_sgn < r_sgn) return true;
if (l_sgn > r_sgn) return false;
int nl = lhs.v.size(), nr = rhs.v.size();
if (l_sgn * nl < r_sgn * nr) return true;
if (l_sgn * nl > r_sgn * nr) return false;
for (int i = nl - 1; i >= 0; i--) {
if (l_sgn * lhs.v[i] < r_sgn * rhs.v[i]) return true;
if (l_sgn * lhs.v[i] > r_sgn * rhs.v[i]) return false;
}
return false;
}
friend bool operator>(const BigInt& lhs, const BigInt& rhs) {
return rhs < lhs;
}
friend bool operator<=(const BigInt& lhs, const BigInt& rhs) {
return !(lhs > rhs);
}
friend bool operator>=(const BigInt& lhs, const BigInt& rhs) {
return rhs <= lhs;
}
friend std::istream& operator>>(std::istream& is, BigInt& rhs) {
std::string s;
is >> s;
rhs = BigInt(s);
return is;
}
friend std::ostream& operator<<(std::ostream& os, const BigInt& rhs) {
if (rhs.sgn < 0) os << "-";
for (int i = int(rhs.v.size()) - 1; i >= 0; i--) {
if (i == int(rhs.v.size()) - 1) {
os << rhs.v[i];
} else {
os << std::to_string(rhs.v[i] + base).substr(1, log10_base);
}
}
return os;
}
private:
static constexpr int base = 10000, log10_base = 4;
static constexpr int naive_mul_threshold = 75;
int sgn;
std::vector<int> v;
BigInt(int sgn, std::vector<int> v) : sgn(sgn), v(v) {}
void normalize() {
while (v.size() >= 2 && v.back() == 0) v.pop_back();
if (v.back() < 0) {
sgn = -sgn;
std::transform(v.begin(), v.end(), v.begin(),
[](int x) { return -x; });
}
int carry = 0;
for (size_t i = 0; i < v.size(); i++) {
v[i] += carry;
if (0 <= v[i] && v[i] < base) {
carry = 0;
continue;
}
carry = div_floor(v[i], base);
v[i] -= carry * base;
}
while (carry > 0) {
v.push_back(carry % base);
carry /= base;
}
while (v.size() >= 2 && v.back() == 0) v.pop_back();
if (v.size() == 1 && v[0] == 0) sgn = 0;
}
template <class T>
static std::vector<int> normalize(const std::vector<T>& c) {
std::vector<int> res(c.size());
T carry = 0;
for (size_t i = 0; i < c.size(); i++) {
T tmp = c[i];
tmp += carry;
if (0 <= tmp && tmp < T(base)) {
carry = 0;
res[i] = int(tmp);
continue;
}
carry = div_floor(tmp, T(base));
res[i] = int(tmp - carry * base);
}
while (carry > 0) {
res.push_back(int(carry % base));
carry /= base;
}
while (res.size() >= 2 && res.back() == 0) res.pop_back();
return res;
}
static std::vector<int> multiply_naive(const std::vector<int>& a,
const std::vector<int>& b) {
std::vector<long long> c(a.size() + b.size() - 1, 0);
for (size_t i = 0; i < a.size(); i++) {
for (size_t j = 0; j < b.size(); j++) {
c[i + j] += a[i] * b[j];
}
}
return normalize(c);
}
static std::vector<long long> multiply_karatsuba(std::vector<long long> a,
std::vector<long long> b) {
int na = a.size(), nb = b.size();
if (std::min(na, nb) <= naive_mul_threshold) {
std::vector<long long> res(a.size() + b.size() - 1, 0);
for (size_t i = 0; i < a.size(); i++) {
for (size_t j = 0; j < b.size(); j++) {
res[i + j] += a[i] * b[j];
}
}
return res;
}
int n = std::max(na, nb);
if (na < n) a.resize(n, 0);
if (nb < n) b.resize(n, 0);
int k = n / 2;
std::vector<long long> x(
std::vector<long long>(a.begin() + k, a.end()));
std::vector<long long> y(
std::vector<long long>(a.begin(), a.begin() + k));
std::vector<long long> z(
std::vector<long long>(b.begin() + k, b.end()));
std::vector<long long> w(
std::vector<long long>(b.begin(), b.begin() + k));
std::vector<long long> xz = multiply_karatsuba(x, z);
std::vector<long long> yw = multiply_karatsuba(y, w);
for (int i = 0; i < k; i++) {
x[i] += y[i];
z[i] += w[i];
}
std::vector<long long> t = multiply_karatsuba(x, z);
for (size_t i = 0; i < xz.size(); i++) {
t[i] -= xz[i] + yw[i];
}
a = std::vector<long long>(2 * k, 0);
a.insert(a.end(), xz.begin(), xz.end());
b = std::vector<long long>(k, 0);
b.insert(b.end(), t.begin(), t.end());
for (size_t i = 0; i < b.size(); i++) {
a[i] += b[i];
}
for (size_t i = 0; i < yw.size(); i++) {
a[i] += yw[i];
}
return a;
}
static void shift_r(BigInt& a, size_t len) {
if (a == 0) return;
if (a.v.size() <= len) {
a = 0;
return;
}
a.v.erase(a.v.begin(), a.v.begin() + len);
}
static BigInt divide_newton_raphson(BigInt a, BigInt b) {
a.sgn = b.sgn = 1;
if (a < b) return 0;
size_t len = a.v.size() + 2;
BigInt x = base * base, prv = x;
while (true) {
BigInt tmp = x * x * b;
shift_r(tmp, len);
x += x;
x -= tmp;
if (x.v.size() > len) shift_r(x, x.v.size() - len);
if ((x - prv).v.size() <= 1) break;
prv = x;
}
BigInt res = a * x;
res.v.erase(res.v.begin(), res.v.begin() + len);
if (res * b + b <= a) ++res;
return res;
}
};
} // namespace rklib
using namespace rklib;
using Bint = BigInt;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while(t--) {
Bint A,B,C,X,Y,D;
cin >> A >> B >> C >> X >> Y >> D;
if(D < X) {
cout << A << endl;
continue;
}
Bint ans = (D+X-1)/X*A;
{
Bint now = 0;
now += D/X*A;
now += min(Y,D%X)*B;
now += max(Bint(0),D%X-Y)*C;
ans = min(ans,now);
}
{
Bint now = 0;
now += D/X*A;
Bint rem = D%X,num = D/X;
now += min(rem,num*Y)*B;
now += max(Bint(0),rem-num*Y)*C;
ans = min(ans,now);
}
{
Bint now = A+B*Y;
now += max(Bint(0),D-X-Y)*C;
ans = min(ans,now);
}
if(D >= X+Y) {
Bint now = D/(X+Y)*(A+B*Y);
now += D%(X+Y)*C;
ans = min(ans,now);
}
if(D >= X+Y) {
Bint now = D/(X+Y)*(A+B*Y)+A;
now += max(Bint(0),D%(X+Y)-X)*B;
ans = min(ans,now);
}
cout << ans << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
5 160 27 41 3 12 3 160 27 41 3 12 4 160 27 41 3 12 99 1 999 999 1 99 999 999 999 1 1 99 9999999999999999
output:
160 187 3226 999 10000000000099799
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 42ms
memory: 3692kb
input:
2077 63 88 64 47 55 88 4 75 38 53 33 41 41 1 28 6 13 100 57 88 77 35 5 48 100 36 97 24 93 87 57 25 26 84 62 18 29 11 33 88 86 71 33 16 7 4 73 68 50 65 72 14 43 78 15 31 72 42 39 29 31 10 76 58 35 89 39 55 99 11 16 82 21 18 57 44 80 16 38 31 99 58 59 69 24 22 69 76 14 83 96 40 56 31 14 36 75 84 27 57...
output:
126 4 311 114 400 57 29 561 300 15 62 312 21 76 48 192 150 130 97 636 76 32 112 180 39 138 36 605 30 23 88 76 285 20 330 325 174 128 32 36 1 36 30 24 192 170 17 88 83 102 140 86 52 81 25 44 8 21 180 49 51 145 55 82 31 85 156 70 158 21 84 48 156 51 184 174 156 86 2 73 83 5 200 117 44 6 152 58 122 26 ...
result:
wrong answer 3rd lines differ - expected: '310', found: '311'