QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#677415#5460. Sum of NumbersocharinWA 17ms3872kbC++201.9kb2024-10-26 11:53:102024-10-26 11:53:15

Judging History

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

  • [2024-10-26 11:53:15]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3872kb
  • [2024-10-26 11:53:10]
  • 提交

answer

/*

                                _/                                      _/
       _/_/        _/_/_/      _/_/_/        _/_/_/      _/  _/_/               _/_/_/
    _/    _/    _/            _/    _/    _/    _/      _/_/          _/       _/    _/
   _/    _/    _/            _/    _/    _/    _/      _/            _/       _/    _/
    _/_/        _/_/_/      _/    _/      _/_/_/      _/            _/       _/    _/

*/
#include<bits/stdc++.h>
#define int long long

using namespace std;

struct big{
    string s;
    big(string _s=""){
        s=_s;
        reverse(s.begin(),s.end());
    }
    big operator+(const big&t){
        big c;
        int ss=s.size(),tt=t.s.size();
        bool b=0;
        for(int i=0;i<max(ss,tt);++i){
            int x=0;
            if(i<ss) x+=s[i]-'0';
            if(i<tt) x+=t.s[i]-'0';
            x+=b;
            if(x>=10) b=1,x-=10;
            else b=0;
            c.s.push_back('0'+x);
        }
        if(b) c.s.push_back('1');
        return c;
    }
    bool operator<(const big &t){
        if(s.size()!=t.s.size()) return s.size()<t.s.size();
        int sz=s.size();
        for(int i=sz-1;i>=0;--i){
            if(s[i]<t.s[i]) return 1;
            if(s[i]>t.s[i]) return 0;
        }
        return 0;
    }
};

void solve(){
    int n,m;
    string s;
    cin>>n>>m>>s;
    int x=n/(m+1),y=n%(m+1);
    vector<int>a(m+1);
    for(int i=0;i<y;++i) a[i]=1;
    sort(a.begin(),a.end());
    big res;
    do{
        big ans;
        int lst=0;
        for(int i=0;i<=m;++i){
            string t=s.substr(lst,x+a[i]);
            ans=ans+big(t);
            lst+=x+a[i];
        }
        if(res<ans) res=ans;
    }while(next_permutation(a.begin(),a.end()));
    reverse(res.s.begin(),res.s.end());
    cout<<res.s<<"\n";
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;cin>>T;
    while(T--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3484kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 3872kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

3643487212740800349472686888551814148464560382557782154258648991735463075773466771863277332588565693103301914818440969321433505767069295563754530614887267182613398545970152359449210708177
2649942334464937947227447463303025498371336102030594072667220062367115685025653911100225182500251150989505913132...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '364348721274080034947268688855...2613398545970152359449210708177'