QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524911#5460. Sum of Numberssolar_express#Compile Error//Python31.6kb2024-08-20 10:23:012024-08-20 10:23:02

Judging History

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

  • [2024-08-20 10:23:02]
  • 评测
  • [2024-08-20 10:23:01]
  • 提交

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

  File "answer.code", line 4
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax