結果

問題 No.2261 Coffee
コンテスト
ユーザー siman
提出日時 2023-04-08 20:15:20
言語 C++17(clang)
(clang++ 22.1.2 + boost 1.89.0)
コンパイル:
clang++ -O2 -lm -std=c++1z -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 936 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,671 ms
コンパイル使用メモリ 148,864 KB
実行使用メモリ 8,832 KB
最終ジャッジ日時 2026-04-19 18:55:33
合計ジャッジ時間 15,483 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:8: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   20 |   ll X[N][5];
      |        ^
main.cpp:20:8: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
main.cpp:30:10: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
   30 |     ll V[N];
      |          ^
main.cpp:30:10: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:17:7: note: declared here
   17 |   int N;
      |       ^
2 warnings generated.

ソースコード

diff #
raw source code

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;

  ll X[N][5];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 5; ++j) {
      cin >> X[i][j];
    }
  }

  vector<ll> ans(N, LLONG_MIN);

  for (int mask = 0; mask < (1 << 5); ++mask) {
    ll V[N];
    memset(V, 0, sizeof(V));
    ll min_v = LLONG_MAX;

    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < 5; ++j) {
        if (mask >> j & 1) {
          V[i] += X[i][j];
        } else {
          V[i] -= X[i][j];
        }
      }

      min_v = min(min_v, V[i]);
    }

    for (int i = 0; i < N; ++i) {
      ans[i] = max(ans[i], V[i] - min_v);
    }
  }

  for (int i = 0; i < N; ++i) {
    cout << ans[i] << endl;
  }

  return 0;
}
0