QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#646622#5460. Sum of NumberscrychicWA 130ms3652kbC++174.8kb2024-10-17 02:01:532024-10-17 02:01:53

Judging History

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

  • [2024-10-17 02:01:53]
  • 评测
  • 测评结果:WA
  • 用时:130ms
  • 内存:3652kb
  • [2024-10-17 02:01:53]
  • 提交

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 % 10000);
        t /= 10000;
    }
    if(t) c.push_back(t);
    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 -= 4) {
                    int tmp = 0;
                    int p = 1;
                    for(int k = 0; k < 4; k ++ ){
                        if(z - k >= now)tmp += (s[z - k] - '0') * p;
                        p *= 10;
                    }
                    a.push_back(tmp);
                    // 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;
                }
            }
        }
    }
    has ++;
    other -= k + 1;
    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 -= 4) {
                    int tmp = 0;
                    int p = 1;
                    for(int k = 0; k < 4; k ++ ){
                        if(z - k >= now)tmp += (s[z - k] - '0') * p;
                        p *= 10;
                    }
                    a.push_back(tmp);
                    // 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 << "?" << s.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;
}

详细

Test #1:

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

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 130ms
memory: 3652kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

286183755516647947970677378799138606867646615958794128735093872774957762935663056503435341452643850760388735990935082251928006517442350857537793072219690979786682717925250679901255
13308978966559747740355864065449074348428350483364112711142783648306345795087382456228893436409654653749236740183946316...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '286183755516647947970677378799...9690979786682717925250679901255'