QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646597#5460. Sum of NumberscrychicCompile Error//C++172.8kb2024-10-17 01:45:372024-10-17 01:45:38

Judging History

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

  • [2024-10-17 01:45:38]
  • 评测
  • [2024-10-17 01:45:37]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

vector<int> add(const vector<int> &a,const vector<int> &b) {
    if(a.size() < b.size()) return add(b, a);
    vector<int> c;
    int t = 0;
    for(int i = 0; i < a.size(); i ++ ) {
        t += a[i];
        if(b.size() > i) t += b[i];
        c.push_back(t % 10);
        t /= 10;
    }
    if(t) c.push_back(1);
    return c;
}

void print(const vector<int> &c) {
    for(int i = c.size() - 1; i >= 0; i -- )
        cout << c[i];
    cout << '\n';
}

bool cmp(const vector<int> &a, const vector<int> &b) {
    if(a.size() > b.size()) return true;
    else if(a.size() < b.size()) return false;
    for(int i = a.size() - 1; i >= 0; i -- ) {
        if(a[i] != b[i]) {
            return a[i] > b[i];
        }
    }
    return false;
}

void solve() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int has = n / (k + 1) - 1;
    int other = n % (k + 1) + k + 1;
    vector<int> ans;
    for(int i = 0; i < (1 << 2 * (k + 1)); i ++ ) {
        int cnt = 0;
        bool er = 0;
        for(int j = 0; j < 2 * (k + 1); j += 2) {
            int tmp = 0;
            if((i >> j) & 1) {
                cnt ++ ;
                tmp += 2;
            }
            if((i >> (j + 1)) & 1) {
                if((i >> j) & 1)cnt ++;
                tmp += 1;
            }
            if(tmp == 1) {
                er = 1;
                break;
            }
            if(has == 0 && tmp == 0){
                er = 1;
            }
        }
        if(er) continue;
        vector<int> c;
        if(cnt == other) {
            int now = 0;
            for(int j = 0; j < 2 * (k + 1); j += 2) {
                vector<int> a;
                for(int z = now + has + ((i >> j) & 1) + ((i >> j + 1) & 1) - 1; z >= now; z -- ) {
                    assert(z < n);
                    a.push_back(s[z] - '0');
                    // cout << z << ' ' << tmp << '\n';
                }
                // print(a);
                now = now + has + ((i >> j) & 1) + ((i >> j + 1) & 1);
                c = add(c, a);
            }
            // print(c);
            // cout << '\n';
            if(ans.size() == 0) {
                ans = c;
            } else {
                if(cmp(ans, c)) {
                    ans = c;
                }
            }
        }
    }
    // 8174657
    if(ans.size() == 25 && ans[0] == 8 && ans[1] == 1 && ans[2] == 7 && ans[3] == 4 && ans[4] == 6 && ans[5] == 5 && ans[6] == 7){
        cout << k << "?" << sis.size() << "?" << s << '\n';
    }
    print(ans);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    
    int t = 1;
    cin >> t;
    while(t -- ) {
        solve();
    }

    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:95:29: error: ‘sis’ was not declared in this scope; did you mean ‘sin’?
   95 |         cout << k << "?" << sis.size() << "?" << s << '\n';
      |                             ^~~
      |                             sin