提出 #29757086


ソースコード 拡げる

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  vl a(n);
  rep(i,0,n) cin >> a[i];

  ll omx = *max_element(all(a));
  ll mx = 0;
  ll ans = 0;

  rep(i,0,n) {
    int l = (i+n-1)%n;
    int r = (i+1) % n;
    ll tot = max(0ll, a[i] - a[l] - a[r]);
    if (l == r) tot = 0;
    ans += tot;
    ckmax(mx, a[i] - tot);
  }

  ans += mx;
  if (n < 5 && ans > omx) ans = omx;

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

提出情報

提出日時
問題 C - Circular Addition
ユーザ hoke_t
言語 C++ (GCC 9.2.1)
得点 0
コード長 1252 Byte
結果 WA
実行時間 35 ms
メモリ 4800 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 500
結果
AC × 3
AC × 10
WA × 6
セット名 テストケース
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt
ケース名 結果 実行時間 メモリ
00-sample-001.txt AC 8 ms 3488 KiB
00-sample-002.txt AC 2 ms 3588 KiB
00-sample-003.txt AC 2 ms 3592 KiB
01-001.txt AC 2 ms 3620 KiB
01-002.txt WA 21 ms 4220 KiB
01-003.txt AC 6 ms 3496 KiB
01-004.txt WA 4 ms 3556 KiB
01-005.txt AC 23 ms 4436 KiB
01-006.txt WA 21 ms 3928 KiB
01-007.txt AC 10 ms 3636 KiB
01-008.txt WA 35 ms 4600 KiB
01-009.txt AC 29 ms 4696 KiB
01-010.txt WA 27 ms 4700 KiB
01-011.txt AC 29 ms 4720 KiB
01-012.txt WA 31 ms 4644 KiB
01-013.txt AC 24 ms 4800 KiB