QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766239 | #9552. The Chariot | lmx111 | WA | 101ms | 4736kb | C++20 | 4.1kb | 2024-11-20 16:43:04 | 2024-11-20 16:43:05 |
Judging History
answer
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
struct Big {
int len, s[5000];
Big() { memset(s, 0, sizeof(s)); len = 1; }
Big(int val) { *this = val; }
Big(const char* val) { *this = val; }
Big operator = (int32_t val) {
char s[5000];
sprintf(s, "%lld", val);
*this = s; return *this;
}
Big operator = (const char* val) {
len = strlen(val);
while (len > 1 && val[0] == '0') ++val, len--;
for (int i = 0; i < len; ++i) s[i] = val[len - i - 1] - '0';
return *this;
}
inline void deal() {
while (len > 1 && !s[len - 1]) len--;
}
Big operator + (const Big& a) const {
Big res; res.len = 0;
int top = max(len, a.len), add = 0;
for (int i = 0; add || i < top; ++i) {
int now = add;
if (i < len) now += s[i];
if (i < a.len) now += a.s[i];
res.s[res.len++] = now % 10;
add = now / 10;
}
return res;
}
Big operator - (const Big& a) const {
Big res; res.len = 0; int del = 0;
for (int i = 0; i < len; ++i) {
int now = s[i] - del;
if (i < a.len) now -= a.s[i];
if (now >= 0) del = 0;
else del = 1, now += 10;
res.s[res.len++] = now;
}
res.deal(); return res;
}
Big operator * (const Big& a) const {
Big res; res.len = len + a.len;
for (int i = 0; i < len; ++i)
for (int j = 0; j < a.len; ++j)
res.s[i + j] += s[i] * a.s[j];
for (int i = 0; i < res.len; ++i)
res.s[i + 1] += res.s[i] / 10, res.s[i] %= 10;
res.deal(); return res;
}
Big operator / (const Big& a) const {
Big res, cur; res.len = len;
cur = 0;
for (int i = len - 1; ~i; --i) {
cur = cur * 10, cur.s[0] = s[i];
while (cur >= a)
cur -= a, res.s[i]++;
}
res.deal(); return res;
}
Big operator % (const Big& a) const {
Big res = *this / a;
return *this - res * a;
}
Big operator += (const Big& a) { *this = *this + a; return *this; }
Big operator -= (const Big& a) { *this = *this - a; return *this; }
Big operator *= (const Big& a) { *this = *this * a; return *this; }
Big operator /= (const Big& a) { *this = *this / a; return *this; }
Big operator %= (const Big& a) { *this = *this % a; return *this; }
bool operator < (const Big& a) const {
if (len != a.len) return len < a.len;
for (int i = len - 1; ~i; i--)
if (s[i] != a.s[i]) return s[i] < a.s[i];
return false;
}
bool operator > (const Big& a) const { return a < *this; }
bool operator <= (const Big& a) const { return !(*this > a); }
bool operator >= (const Big& a) const { return !(*this < a); }
bool operator == (const Big& a) const { return !(*this > a || *this < a); }
bool operator != (const Big& a) const { return *this > a || *this < a; }
void print() {
for (int i = this->len - 1; ~i; --i)
printf("%lld", this->s[i]); puts("");
}
void read() {
char d[5000];
scanf("%s", d);
int l = strlen(d);
for (int i = 0; i < l; i++)
this->s[i] = d[l - i - 1] - '0';
len = l;
}
};
void solve(){
Big zero;
zero = 0;
Big A, B, C, D, X, Y;
A.read(); B.read(); C.read(); X.read(); Y.read(); D.read();
if(D <= X) {
A.print();
}
else if(X < D and D <= X + Y) {
Big ans = A + B * (D - X);
if(ans > A * (D / X + (D % X != zero))) ans = A * (D / X + (D % X != zero));
if(ans > (D / X) * A + (D % X) * B) ans = (D / X) * A + (D % X) * B;
ans.print();
} else {
Big ans = A + B * Y + C * (D - X - Y);
Big ans1 = (D / X + (D % X != zero)) * A;
if(ans > ans1) ans = ans1;
if(D % X <= Y) ans1 = (D / X) * A + (D % X) * B;
else ans1 = (D / X) * A + (D % X - Y) * C + B * Y;
if(ans > ans1) ans = ans1;
ans1 = (D / (X + Y)) * (A + B * Y);
if(D % (X + Y) <= X) {
ans1 += A;
if((D / (X + Y)) * Y >= (X - D % (X + Y))) ans1 -= (X - D % (X + Y)) * B;
else ans1 -= (D / (X + Y)) * Y * B;
}
else ans1 += A + (D % (X + Y) - X) * B;
if(ans > ans1) ans = ans1;
ans1 = (D / (X + Y)) * (B * Y + A) + C * (D % (X + Y));
if(ans > ans1) ans = ans1;
if((D / X) * Y > D % X) ans1 = A * (D / X) + Y * (D % X);
if(ans > ans1) ans = ans1;
ans.print();
}
}
int32_t main()
{
int tc;
cin >> tc;
while(tc--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 4696kb
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: 101ms
memory: 4736kb
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 310 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 290 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 145 174 156 86 2 73 83 5 200 117 44 6 152 58 122 26 ...
result:
wrong answer 35th lines differ - expected: '330', found: '290'