QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#521935#5460. Sum of Numbersno_RED_no_DEADCompile Error//C++202.8kb2024-08-16 16:44:142024-08-16 16:44:15

Judging History

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

  • [2024-08-16 16:44:15]
  • 评测
  • [2024-08-16 16:44:14]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

const ll N = 1e6 + 1;
const ll M = 1e9 + 7;

ll n, k, avg;
string res;
string s;

string add(string str1, string str2) 
{ 
    // Remove leading zeros from both strings
    str1.erase(0, min(str1.find_first_not_of('0'), str1.size()-1));
    str2.erase(0, min(str2.find_first_not_of('0'), str2.size()-1));
 
    // If both strings become empty, return "0"
    if (str1.empty() && str2.empty()) 
        return "0";
 
    // Before proceeding further, make sure length 
    // of str2 is larger. 
    if (str1.length() > str2.length()) 
        swap(str1, str2); 
 
    // Take an empty string for storing result 
    string str = ""; 
 
    // Calculate length of both string 
    int n1 = str1.length(), n2 = str2.length(); 
    int diff = n2 - n1; 
 
    // Initially take carry zero 
    int carry = 0; 
 
    // Traverse from end of both strings 
    for (int i=n1-1; i>=0; i--) 
    { 
        // Do school mathematics, compute sum of 
        // current digits and carry 
        int sum = ((str1[i]-'0') + 
                (str2[i+diff]-'0') + 
                carry); 
        str.push_back(sum%10 + '0'); 
        carry = sum/10; 
    } 
 
    // Add remaining digits of str2[] 
    for (int i=n2-n1-1; i>=0; i--) 
    { 
        int sum = ((str2[i]-'0')+carry); 
        str.push_back(sum%10 + '0'); 
        carry = sum/10; 
    } 
 
    // Add remaining carry 
    if (carry) 
        str.push_back(carry+'0'); 
 
    // reverse resultant string 
    reverse(str.begin(), str.end()); 
 
    return str; 
} 

string cmin(string &a, string &b) {
    if (a.size() < b.size()) return a;
    if (a.size() > b.size()) return b;
    return (a < b) ? a : b;
}

void backtrack(ll pos, ll len, string sum, ll st, ll lastLen) {
    if (pos > k) {
        if (len != n) return;
        res = cmin(res, sum);
        return;
    }
    for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
        ll npos = pos + 1, nlen = len + i, nst = st + i;
        string nsum = sum;

        if (nlen > n) break;
        if (len + (n - pos + 1) * (avg + 2) < n) continue;

        string t;
        for (int j = st; j <= st + i - 1; j ++) t += s[j];
        nsum = add(sum, t);
        backtrack(npos, nlen, nsum, nst, i);
    }
}

void doTest(ll testID) {
    cin >> n >> k; k ++;
    cin >> s; s = ' ' + s; 
    res = ""; for (int i = 1; i <= n; i ++) res += '9'; 
    avg = n / k;
    for (int i = max(1ll, avg - 1); i <= avg + 1; i ++) backtrack(1, 0, "0", 1, i); 
    cout << res << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int test = 1; 
    cin >> test;
    for (int _ = 1; _ <= test; _ ++) doTest(test);
}

Details

answer.code: In function ‘void backtrack(ll, ll, std::string, ll, ll)’:
answer.code:79:63: error: no matching function for call to ‘min(long double, ll)’
   79 |     for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
      |                                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:233:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)’
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
answer.code:79:63: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long double’ and ‘ll’ {aka ‘long long int’})
   79 |     for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
      |                                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)’
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:281:5: note:   template argument deduction/substitution failed:
answer.code:79:63: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long double’ and ‘ll’ {aka ‘long long int’})
   79 |     for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
      |                                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5775:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)’
 5775 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5775:5: note:   template argument deduction/substitution failed:
answer.code:79:63: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long double’
   79 |     for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
      |                                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)’
 5785 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5785:5: note:   template argument deduction/substitution failed:
answer.code:79:63: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long double’
   79 |     for (int i = max(avg - 1, max(1ll, lastLen - 1)); i <= min(ceill((long double)n / k) + 1, lastLen + 1); i ++) {
      |                                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~