結果
| 問題 |
No.1150 シュークリームゲーム(Easy)
|
| コンテスト | |
| ユーザー |
mtsd
|
| 提出日時 | 2020-08-07 21:46:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,931 bytes |
| コンパイル時間 | 1,149 ms |
| コンパイル使用メモリ | 120,464 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-09-24 19:42:15 |
| 合計ジャッジ時間 | 4,684 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | TLE * 1 -- * 42 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
std::fill( (T*)array, (T*)(array+N), val );
}
template<class T> inline bool chmax(T &a, T b){
if(a<b){
a = b;
return true;
}
return false;
}
template<class T> inline bool chmin(T &a, T b){
if(a>b){
a = b;
return true;
}
return false;
}
int main(){
int n;
cin >> n;
int s,t;
cin >> s >> t;
s--;t--;
vector<ll> a(n);
rep(i,n) cin >> a[i];
ll sm = accumulate(all(a),0LL);
int L = 0;
int R = 0;
int b = s;
int c = t;
bool f = 0;
while(abs(b-c)>1){
if(!f){
f = 1;
b++;
if(b>=n)b-=n;
if(b==c){
b--;
if(b<0)b+=n;
break;
}
}else{
f = 0;
c--;
if(c<0)c+=n;
}
}
L = b;
b = s;
c = t;
f = 0;
while(abs(b-c)>1){
if(!f){
f = 1;
b--;
if(b<0)b+=n;
if(b==c){
b++;
if(b>=n)b-=n;
break;
}
}else{
f = 0;
c++;
if(c>=n)c-=n;
}
}
R = b;
if(L>R){
swap(L,R);
}
cerr << L << " " << R << endl;
int m;
if(n%2==0){
m = n/2;
}else{
m = n/2+1;
}
ll mx = 0;
if(s>=L){
ll t = 0;
int p,q;
for(int i=0;i<m;i++){
t += a[(L+i)%n];
}
mx = t;
p = L;
q = (L+m)%n;
while((q+m-1)%m!=R){
// cerr << p << " " << t << endl;
t -= a[p];
t += a[q];
p++;
q++;
p%=n;
q%=n;
chmax(mx,t);
}
}else{
ll t = 0;
int p,q;
for(int i=0;i<m;i++){
t += a[(R+i)%n];
}
mx = t;
p = R;
q = (R+m)%n;
while((q+m-1)%m!=L){
t -= a[p];
t += a[q];
p++;
q++;
p%=n;
q%=n;
chmax(mx,t);
}
}
cout << mx - (sm-mx) << endl;
return 0;
}
mtsd