結果
問題 | No.1150 シュークリームゲーム(Easy) |
ユーザー |
![]() |
提出日時 | 2020-08-07 22:53:49 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 2,200 bytes |
コンパイル時間 | 1,584 ms |
コンパイル使用メモリ | 172,360 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 23:17:21 |
合計ジャッジ時間 | 3,841 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)#define rep(i,n) REP(i,0,n)#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)#define ALLOF(c) (c).begin(), (c).end()typedef long long ll;typedef unsigned long long ull;int main(){int N;cin >> N;int s, t;cin >> s >> t;s--; t--;vector<ll> tmp;rep(i,N){ll a;cin >> a;tmp.push_back(a);}vector<ll> v;rep(i,N){v.push_back(tmp[(s+i)%N]);}t = (t+N-s)%N;s = 0;ll X = v[s], Y = v[t];int rhs = t-1-s;int lhs = N-2-rhs;if(lhs%2==0 && rhs%2==0){{int p = s, q = t;while(true){p++; q--;if(p==(q+1)%N) break;X += v[p];Y += v[q];}}{int p = s, q = t;while(true){p=(p-1+N)%N;q=(q+1)%N;if(q==(p+1)%N) break;X += v[p];Y += v[q];}}}if(lhs%2==0 && rhs%2==1){{int p = s, q = t;while(true){p++; q--;X += v[p];if(p==q) break;Y += v[q];}}{int p = s, q = t;while(true){p=(p-1+N)%N;q=(q+1)%N;if(q==(p+1)%N) break;X += v[p];Y += v[q];}}}if(lhs%2==1 && rhs%2==0){{int p = s, q = t;while(true){p++; q--;if(p==(q+1)%N) break;X += v[p];Y += v[q];}}{int p = s, q = t;while(true){p=(p-1+N)%N;q=(q+1)%N;X += v[p];if(q==p) break;Y += v[q];}}}if(lhs%2==1 && rhs%2==1){int pp, qq;{int p = s, q = t;while(true){p++; q--;if(p==q) break;X += v[p];Y += v[q];}pp = p;}{int p = s, q = t;while(true){p=(p-1+N)%N;q=(q+1)%N;if(p==q) break;X += v[p];Y += v[q];}qq = p;}if(v[pp] > v[qq]){X += v[pp];Y += v[qq];}else{X += v[qq];Y += v[pp];}}cout << X - Y << endl;return 0;}