QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524914#5460. Sum of Numberssolar_express#WA 5ms3792kbC++231.6kb2024-08-20 10:23:182024-08-20 10:23:19

Judging History

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

  • [2024-08-20 10:23:19]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:3792kb
  • [2024-08-20 10:23:18]
  • 提交

answer

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

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';
      memcpy(ans, s, n);
      lenans = n;
      reverse(s, s+n);
      vector<int> len(k, n/k);
      for (int i = 0; i < n%k; ++i) len[k-i-1]+=1;
      int ul = (n%k)? n/k+1:n/k;
      do {
        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;
        }

      } while (next_permutation(begin(len), end(len)));
      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: 3584kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

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

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

2662532599281321175958692727453282666820695061249916500598706091484120361314167711764632270437976580885204989240079393094942894325034066469398379425200487015287025128081632817210198534218
2053211800248783282479102996897759512788183578518469981003613555399248795662771251145530572542224249364024127814...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '266253259928132117595869272745...5287025128081632817210198534218'