結果
問題 | No.1150 シュークリームゲーム(Easy) |
ユーザー |
![]() |
提出日時 | 2020-08-09 01:59:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 1,658 bytes |
コンパイル時間 | 926 ms |
コンパイル使用メモリ | 94,340 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-02 13:22:38 |
合計ジャッジ時間 | 2,819 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
/* -*- coding: utf-8 -*-** 1150.cc: No.1150 シュークリームゲーム(Easy) - yukicoder*/#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<deque>#include<algorithm>#include<numeric>#include<utility>#include<complex>#include<functional>using namespace std;/* constant */const int MAX_N = 100000;const int MAX_N2 = MAX_N * 2;const long long LINF = 1LL << 62;/* typedef */typedef long long ll;/* global variables */int as[MAX_N2];ll ass[MAX_N2 + 1];/* subroutines *//* main */int main() {int n, s, t;scanf("%d%d%d", &n, &s, &t);s--, t--;int n2 = n * 2;for (int i = 0; i < n; i++) scanf("%d", as + i), as[i + n] = as[i];for (int i = 0; i < n2; i++) ass[i + 1] = ass[i] + as[i];int s0, t0, t1, s1;if (s < t)s0 = s, t0 = t1 = t, s1 = s + n;elses0 = s, t0 = t + n, t1 = t, s1 = s;int k = t0 - (s0 + 1), l = s1 - (t1 + 1);int hk = k / 2, hl = l / 2;int w0 = t0 - hk, w1 = t1 + 1 + hl;ll x = as[s], y = as[t];if (! (k & 1) || ! (l & 1)) {x += (ass[w0] - ass[s0 + 1]) + (ass[s1] - ass[w1]);y += (ass[t0] - ass[w0]) + (ass[w1] - ass[t1 + 1]);}else {if (as[w0 - 1] > as[w1]) {x += (ass[w0] - ass[s0 + 1]) + (ass[s1] - ass[w1 + 1]);y += (ass[t0] - ass[w0]) + (ass[w1 + 1] - ass[t1 + 1]);}else {x += (ass[w0 - 1] - ass[s0 + 1]) + (ass[s1] - ass[w1]);y += (ass[t0] - ass[w0 - 1]) + (ass[w1] - ass[t1 + 1]);}}printf("%lld\n", x - y);return 0;}