QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#768060#5460. Sum of NumberswxhtzdyWA 20ms3996kbC++201.8kb2024-11-21 00:04:172024-11-21 00:04:17

Judging History

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

  • [2024-11-21 00:04:17]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3996kb
  • [2024-11-21 00:04:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    k += 1;
    string s;
    cin >> s;
    vector<int> g;
    for (int i = 0; i < k; i++) {
      g.push_back(n / k);
    }
    auto Add = [&](string s, string t) {
      reverse(s.begin(), s.end());
      reverse(t.begin(), t.end());
      int carry = 0;
      int ptr = 0;
      string res = "";
      while (ptr < int(s.size()) || ptr < int(t.size()) || carry != 0) {
        int ds = (ptr < int(s.size()) ? int(s[ptr] - '0') : 0);
        int dt = (ptr < int(t.size()) ? int(t[ptr] - '0') : 0);
        int d = (ds + dt + carry) % 10;
        res += char('0' + d);
        carry = (ds + dt + carry) / 10;
        ptr += 1;
      }
      reverse(res.begin(), res.end());
      return res;
    };
    int c = (n / k) * k;
    string res = "";
    for (int mask = 0; mask < (1 << k); mask++) {
      if (c + __builtin_popcount(mask) != n) {
        continue;
      }
      for (int i = 0; i < k; i++) {
        if (mask >> i & 1) {
          g[i] += 1;
        }
      }
      int ptr = 0;
      string sum = "0";
      for (int i = 0; i < k; i++) {
        string cur = "";
        for (int j = 0; j < g[i]; j++) {
          cur += s[ptr];
          ptr += 1;
        }
        sum = Add(sum, cur);
      }
      if (res.empty()) {
        res = sum;
      } else {
        if (int(res.size()) > int(sum.size())) {
          res = sum;
        } else {
          res = min(res, sum);
        }
      }
      for (int i = 0; i < k; i++) {
        if (mask >> i & 1) {
          g[i] -= 1;
        }
      }
    }
    cout << res << '\n';
  }
  return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 20ms
memory: 3656kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2861837555106640794797067737879913860686764066159587941287350938727749577629356630565034353414526438507603808735990935008225192080065174423508575377930722196909797866802717925250679901255
1330897896655974774035586406544907434842835048336411271110427836483063457950873824562288934364096546537492367401...

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3764kb

input:

3
68312 1
97721793232462295468345161395388245623318759168492992575579675893432997968276399269361852215552871434587866112799189725614696256526239439933158479577223186954475137216722241699568491426254779997896288355965839555276546655174417599498493234323661877664997543475525992228661739933395881544363...

output:

165361439370989969611281150911906045608758081895436745302721903170895741831200164992289491213814537683869854746077326282091529052307364873668669947061960472772133388934416763345394409983809105665214082485429685401199520114459892594221344388768178495952936142426649338494017013932243993161711816767032...

result:

ok 3 lines

Test #4:

score: 0
Accepted
time: 5ms
memory: 3704kb

input:

3
104062 2
6586987777965872861989232258194733262765989634859654379877935579528781688159322513128986886481716832258115626748535521126479244461411522889744479186513298679746684345233214226141199846787117661159318966767135455745184384324833645134232699525177668629239933843658643667417337451334591594819...

output:

536246497591460214899497073157707308719964754106858053886979792537707870310253164299747153718261114131636990130350872742851787818427135113617679220183754863021102973854172956224432906133335696002890140207617299467927865340000078212572980076032917286214327823207585568582552662612028254042515906063023...

result:

ok 3 lines

Test #5:

score: -100
Wrong Answer
time: 6ms
memory: 3996kb

input:

3
139639 3
6796297676823528648589397343663999328612414278384367347213637689464348185237425534836886677731351726963453579377613988437426483671299519186839344132333793569544718489728294346989818592279444871423953477919473799463194216678119582972131632322347549538925164854516141164554772823372476647126...

output:

126364763403906564661708542497996384758493064461499142133308596067494936258655259133526434841726196274703766844552726915088706942994746309192813887599486034682622494344506129054929148805249803660505979746418821689885230718372401950523582639142168746487771785553740446005221635828358569536474437471762...

result:

wrong answer 3rd lines differ - expected: '915515775070779648534953934018...8633672275746392080250748676804', found: '100333642403503063302631765847...8035850375658127196974481909678'