QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#810280#9552. The Chariotfrankly6WA 17ms4064kbC++205.0kb2024-12-11 20:51:492024-12-11 20:51:54

Judging History

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

  • [2024-12-11 20:51:54]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:4064kb
  • [2024-12-11 20:51:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<cassert>
using namespace std;

int T;
struct HugeInt
{
    typedef unsigned long long ll;
    static const int BASE=100000000;
    static const int WIDTH=8;
    vector<int> s;
    HugeInt &clean()
    {
        while(!s.back()&&s.size()>1)
            s.pop_back();
        return *this;
    }
    HugeInt(ll num=0) {*this=num;}
    HugeInt(string s) {*this=s;}
    HugeInt &operator = (ll num)
    {
        s.clear();
        do{
            s.push_back(num%BASE);
            num/=BASE;
        } while(num>0);
        return *this;
    }
    HugeInt &operator=(const string &str)
    {
        s.clear();
        int x, len=(str.length()-1)/WIDTH+1;
        for(int i=0;i<len;i++)
        {
            int end=str.length()-i*WIDTH;
            int start=max(0,end-WIDTH);
            sscanf(str.substr(start,end-start).c_str(),"%d",&x);
            s.push_back(x);
        }
        return (*this).clean();
    }
    HugeInt operator + (const HugeInt &b)const{
        HugeInt c; c.s.clear();
        for(int i=0,g=0;;i++)
        {
            if(g==0&&i>=s.size()&&i>=b.s.size()) break;
            int x=g;
            if(i<s.size()) x+=s[i];
            if(i<b.s.size()) x+=b.s[i];
            c.s.push_back(x%BASE);
            g = x/BASE;
        }
        return c;
    }
    HugeInt operator - (const HugeInt &b)const{
        HugeInt c; c.s.clear();
        for(int i=0,g=0;;i++)
        {
            if(g==0&&i>=s.size()&&i>=b.s.size()) break;
            int x=s[i]+g;
            if(i<b.s.size()) x-=b.s[i];
            if(x<0) g=-1, x+=BASE; 
            else g=0;
            c.s.push_back(x);
        }
        return c.clean();
    }
    HugeInt operator * (const HugeInt &b)const{
        int i, j; ll g;
        vector<ll> v(s.size()+b.s.size(),0);
        HugeInt c; c.s.clear();
        for(i=0;i<s.size();i++)
            for(j=0;j<b.s.size();j++)
                v[i+j]+=ll(s[i])*b.s[j];
        for(i=0, g=0;;i++)
        {
            if(g==0&&i>=v.size()) break;
            ll x=v[i]+g;
            c.s.push_back(x%BASE);
            g=x/BASE;
        }
        return c.clean();
    }
    HugeInt operator / (const HugeInt &b)const{
        HugeInt c = *this;
        HugeInt m;
        for(int i=s.size()-1;i>=0;i--)
        {
            m = m*BASE+s[i];
            c.s[i] = bsearch(b,m);
            m -= b*c.s[i];
        }
        return c.clean();
    }
    HugeInt operator % (const HugeInt &b)const{
        HugeInt c = *this;
        HugeInt m;
        for(int i=s.size()-1;i>=0;i--)
        {
            m=m*BASE+s[i];
            c.s[i]=bsearch(b,m);
            m-=b*c.s[i];
        }
        return m;
    }
    int bsearch(const HugeInt &b, const HugeInt &m)const{
        int L=0, R=BASE-1, x;
        while(L<=R)
        {
            x=(L+R)>>1;
            if(b*x<=m)
            {
                if(b*(x+1)>m) return x; 
                else L=x+1;
            } 
            else R=x-1;
        }
    }
    HugeInt& operator -= (const HugeInt &b) {*this = *this-b; return *this;}
    bool operator < (const HugeInt &b)const{
        if(s.size()!=b.s.size()) return s.size()<b.s.size();
        for(int i=s.size()-1;i>=0;i--)
            if(s[i]!=b.s[i]) return s[i]<b.s[i];
        return false;
    }
    bool operator > (const HugeInt &b)const{return b<*this;}
    bool operator <= (const HugeInt &b)const{return !(b<*this);}
    bool operator == (const HugeInt &b)const{return !(b<*this)&&!(b>*this);}
}A, B, C, X, Y, D;
ostream& operator << (ostream &out, const HugeInt &x)
{
    out << x.s.back();
    for(int i=x.s.size()-2;i>=0;i--)
    {
        char buf[20];
        sprintf(buf,"%08d",x.s[i]);
        for(int j=0;j<strlen(buf);j++) out << buf[j];
    }
    return out;
}
istream& operator >> (istream &in, HugeInt &x)
{
    string s;
    if(!(in>>s)) return in;
    x=s; return in;
}
HugeInt min(HugeInt a, HugeInt b) {return a<=b?a:b;}
int main()
{
    // freopen("testdata.in","r",stdin);
    cin >> T;
    while(T--)
    {
        cin >> A >> B >> C >> X >> Y >> D;
        // cout << A << " " << B << " " << C << " " << X << " " << Y << " " << D << " " << '\n';
        HugeInt c1, c2, c3;
        if(D<=X) {cout << A << '\n'; continue;}
        if(D<=X+Y) c1=A*B+(D-X);
        else c1=A+B*Y+C*(D-X-Y);
        HugeInt cA, nA, left;
        cA=(D/X)*A;
        nA=D/X;
        left=D-nA*X; 
        if(nA*Y<left) c2 = cA+min(nA*Y*B+(left-nA*Y)*C, Y*B+(left-Y)*C);
        else if(Y<=left) c2 = cA+min(left*B, Y*B+(left-Y)*C);
        else c2 = cA+left*B;
        c2=min(c2,cA+A);
        HugeInt bD=X+Y, bC=A+B*Y, cAB, nAB;
        cAB=(D/bD)*bC;
        nAB=D/bD;
        left=D-D/bD*bD; 
        if(left<X) c3 = cAB+A-min(nAB*Y,X-left)*B; 
        else c3 = cAB+A+(left-X)*B;
        if(D>X+Y) c3 = min(c3,cAB+C*left);
        cout << min(c1,min(c2,c3)) << '\n';
    }
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4064kb

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: 17ms
memory: 3752kb

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
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
145
174
156
86
2
73
83
5
200
117
44
6
152
58
122
26
...

result:

wrong answer 455th lines differ - expected: '229', found: '167'