QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524967#5460. Sum of Numberssolar_express#WA 955ms3880kbC++231.9kb2024-08-20 11:06:452024-08-20 11:06:45

Judging History

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

  • [2024-08-20 11:06:45]
  • 评测
  • 测评结果:WA
  • 用时:955ms
  • 内存:3880kb
  • [2024-08-20 11:06:45]
  • 提交

answer

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
using namespace std;
const int N = 3e5+5, M = 2e6;
int n, k, base;
char s[N];
char res[N];
char ans[N];
int lenans;

void update_ans(vector<int> len) {
  int ul = *max_element(begin(len), end(len));
        vector<int> p(k);
        for (int i = 1; i < k; ++i) p[i] += len[i-1];
        char carry = 0;
        int lenres = 0;
        for (int i = 0; i < ul; ++i) {
          char cur = carry;
          for (int j = 0; j < k; ++j) if (i < len[j]) {
            cur += s[p[j]+i];
          }
          res[i] = cur % 10;
          carry = cur / 10;
          ++lenres;
        }
        if (carry) res[lenres++] = carry;
        bool upd = 0;
        if (lenres < lenans) upd = 1;
        else if (lenres == lenans) {
          for (int i = lenres - 1; i >= 0; --i) {
            if (res[i] < ans[i]) {
              upd = 1;
              break;
            }
          }
        }
        if (upd) {
          for (int i = 0; i < lenres; ++i) ans[i] = res[i];
          lenans = lenres;
        }
}

vector<int> p;

void dfs(int i, int s) {
  if (i == k) {
    if (s == n) {
      update_ans(p);
    }
    return;
  }
  for (p[i] = max(1, base-2); p[i] < base+3; ++p[i]) {
    dfs(i+1, s+p[i]);
  }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--) {
      cin >> n >> k >> s;
      k = min(k+1, n);
      for (int i = 0; i < n; ++i) s[i] -= '0';
      lenans = n;
      reverse(s, s+n);
      base = n/k;
      memcpy(ans, s, n);
      // vector<int> len(k, n/k);
      // for (int i = 0; i < n%k; ++i) len[k-i-1]+=1;
      // update_ans(len);
      p.resize(k);
      dfs(0,0);
      for (int i = lenans-1; i >= 0; --i) {
        cout << char(ans[i]+'0');
      }
      cout << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 955ms
memory: 3792kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

8731577739861156033781152792603716183733471595325946452742990275499531076790652455126326859773557644152409631457051333601055453950530531274627399461951339341938188291232207057403103047406
9923410561168937637661946628326178332526754855382338700330116128071138181448874450807324275490482036922277234026...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '873157773986115603378115279260...1938188291232207057403103047406'