QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602950#6443. Windblume Festivalucup-team3519#Compile Error//C++171.2kb2024-10-01 13:45:102024-10-01 13:45:12

Judging History

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

  • [2024-10-01 13:45:12]
  • 评测
  • [2024-10-01 13:45:10]
  • 提交

answer

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

using i64 = int64_t;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }

    if (std::all_of(a.begin(), a.end(), [](int x) {
            return x <= 0;
        })) {
        for (int &i : a) {
            i = -i;
        }
    }

    bool neg = false, pos = false;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= 0)
            neg = true;
        if (a[i] >= 0)
            pos = true;
    }
    if (neg && pos) {
        i64 ans = 0;
        for (int i = 0; i < n; ++i) {
            if (a[i] < 0) {
                ans += -a[i];
            } else {
                ans += a[i];
            }
        }
        std::cout << ans << '\n';
    } else {
        std::cout << std::accumulate(a.begin(), a.end(), 0LL) -
                         *std::min_element(a.begin(), a.end()) * 2LL
                  << '\n';
    }
}

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

    int t;
    std::cin >> t;

    while (t--) {
        solve();
    }
}

Details

answer.code: In function ‘void solve()’:
answer.code:16:14: error: ‘all_of’ is not a member of ‘std’
   16 |     if (std::all_of(a.begin(), a.end(), [](int x) {
      |              ^~~~~~
answer.code:43:32: error: ‘min_element’ is not a member of ‘std’; did you mean ‘tuple_element’?
   43 |                          *std::min_element(a.begin(), a.end()) * 2LL
      |                                ^~~~~~~~~~~
      |                                tuple_element