QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#627505#6443. Windblume FestivalMahnoKropotkinov#Compile Error//C++201.3kb2024-10-10 16:09:512024-10-10 16:09:51

Judging History

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

  • [2024-10-10 16:09:51]
  • 评测
  • [2024-10-10 16:09:51]
  • 提交

answer

#include <iostream>
#include <vector>

using namespace std;
using i64 = long long;

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

  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;

    vector a(n, 0);
    for (auto& i : a) {
      cin >> i;
    }

    if (n == 1) {
      cout << a.front() << '\n';
      continue;
    } else if (n == 2) {
      cout << max(a.front() - a.back(), a.back() - a.front()) << '\n';
      continue;
    }

    i64 sum = 0;
    bool pos = false, neg = false;
    for (auto& x : a) {
      pos |= x > 0;
      neg |= x < 0;
      sum += abs(x);
    }
    // cerr << sum << '\n';

    if (pos and neg) {
      cout << sum << '\n';
      continue;
    }

    if (count(a.begin(), a.end(), a.front()) == n) {
      cout << (n - 2ll) * abs(a.front()) << '\n';
      continue;
    }

    i64 ans = 0;
    if (pos) {
      for (int i = 0; i < n; i++) {
        int x = a[i], y = a[(i + 1) % n];
        if (x - y < 0) {
          ans = max(ans, sum - x * 2);
        }
      }
    } else {
      for (int i = 0; i < n; i++) {
        int x = a[i], y = a[(i + 1) % n];
        if (x - y > 0) {
          ans = max(ans, sum + x * 2);
        }
      }
    }

    cout << ans << '\n';
  }

  return 0;
}

详细

answer.code: In function ‘int main()’:
answer.code:44:9: error: ‘count’ was not declared in this scope
   44 |     if (count(a.begin(), a.end(), a.front()) == n) {
      |         ^~~~~