QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400747#5460. Sum of NumbersiwewWA 12ms4448kbC++202.5kb2024-04-27 15:50:022024-04-27 15:50:04

Judging History

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

  • [2024-04-27 15:50:04]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4448kb
  • [2024-04-27 15:50:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N = 200010;

int A[N], B[N], C[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T -- ) {
        int n, k;
        string str;
        cin >> n >> k >> str;
        reverse(str.begin(), str.end());

        int rem = n % (k + 1), d = n / (k + 1);
        vector<int> states;
        for(int i = 0; i < (1 << (k + 1)); i ++ ) {
            int cnt = 0;
            for(int j = 0; j < k + 1; j ++ ) cnt += (i >> j & 1);
            if(cnt == rem) {
                states.push_back(i);
            }
        }

        auto getval = [&](int v[], int l, int r) -> void {
            for(int i = 0; i < r - l + 1; i ++ ) {
                v[i] = str[l + i] - '0';
            }
        };

        auto add = [&](int v1[], int v2[], int &len1, int len2) -> void {
            int t = 0;
            len1 = max(len1, len2);
            for(int i = 0; i < len2; i ++ ) {
                t += v1[i] + v2[i];
                v1[i] = t % 10;
                t /= 10;
            }
            for(int i = len2; i < len1; i ++ ) {
                t += v1[i];
                v1[i] = t % 10;
                t /= 10;
            }
            while(t) {
                v1[len1 ++ ] = t % 10;
                t /= 10;
            }
        };

        auto take = [&](int v1[], int v2[], int &len1, int &len2) -> void {
            bool high = true;
            if(len1 != len2 && len1 < len2) high = false;
            else if(len1 == len2) {
                for(int i = len1 - 1; i >= 0; i -- ) {
                    if(v1[i] != v2[i]) {
                        if(v1[i] < v2[i]) high = false;
                        break;
                    }
                }
            }
            if(!high) {
                len1 = len2;
                for(int i = len2 - 1; i >= 0; i -- ) v1[i] = v2[i];
            }
        };

        int m = 0;
        for(int i = 0; i < n + 5; i ++ ) C[i] = 0;
        for(auto state : states) {
            int len = 0, last = -1;
            for(int i = 0; i < n + 5; i ++ ) A[i] = B[i] = 0;
            for(int j = 0; j < k + 1; j ++ ) {
                int l = last + 1, r = (state >> j & 1 ? l + d : l + d - 1);
                getval(B, l, r);
                add(A, B, len, r - l + 1);
                last = r;
            }
            take(C, A, m, len);
        }
        for(int i = m - 1; i >= 0; i -- ) cout << C[i];
        cout << '\n';
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

2
8 1
45455151
2 1
42

output:

9696
6

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 12ms
memory: 4448kb

input:

10
1301 6
56328399613959594774559774218276494124991536454496431869449134772679831477279356599352619469813771742358572734317965823527349354276551857226632977613336815474383422853946661428822284645652423563864641261338984158269966469425994769486371736593879954275146732544891889693921182364554588732946...

output:

3643487212740800349472686888551814148464560382557782154258648991735463075773466771863277332588565693103301914818440969321433505767069295563754530614887267182613398545970152359449210708177
2649942334464937947227447463303025498371336102030594072667220062367115685025653911100225182500251150989505913132...

result:

wrong answer 1st lines differ - expected: '286183755510664079479706773787...6909797866802717925250679901255', found: '364348721274080034947268688855...2613398545970152359449210708177'