QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#752446#7695. Double UpalexhamidiWA 0ms3592kbC++141.3kb2024-11-16 03:27:272024-11-16 03:27:28

Judging History

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

  • [2024-11-16 03:27:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-11-16 03:27:27]
  • 提交

answer

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

auto cmp = [](const string& a, const string& b) {
    if (a.size() != b.size()) {
        return a.size() < b.size();
    }
    return a < b;
};



string times2(const string& s) {
    string res = "";
    int carry = 0;
    int n = s.size(); // fails 16 4 1 4 16


    for (int i = n-1; i >= 0; i--) {
        int digitVal = (s[i]-'0')*2 + carry;
        res.push_back(digitVal%10 + '0');
        carry = digitVal/10;
    }

    if (carry > 0) {
        res.push_back('1');
    }

    reverse(res.begin(), res.end());

    return res;
}


int main() {
    int n;
    cin >> n;
    vector<string> A(n);
    for (auto& a : A) cin >> a;

    while (A.size() > 1) {
        bool merged = false;

        for (int i = 0; i < A.size()-1; i++) {
            if (A[i] == A[i+1]) {
                A[i] = times2(A[i]);
                A.erase(A.begin() + i + 1);
                merged = true;
            }
        }

        if (!merged && A.size() > 1) {
            A.erase(min_element(A.begin(), A.end(), cmp)); //this is not working
        }
        for (auto& a : A) cout << a << " ";
        cout <<"\n";
    }
    cout << A[0];
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3592kb

input:

5
4 2 2 1 8

output:

4 4 1 8 
8 1 8 
8 8 
16 
16

result:

wrong answer 1st lines differ - expected: '16', found: '4 4 1 8 '