結果

問題 No.1150 シュークリームゲーム(Easy)
ユーザー LayCurseLayCurse
提出日時 2020-08-07 21:44:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 3,055 bytes
コンパイル時間 2,494 ms
コンパイル使用メモリ 214,212 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2023-10-25 00:33:56
合計ジャッジ時間 4,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,636 KB
testcase_01 AC 3 ms
5,636 KB
testcase_02 AC 2 ms
5,636 KB
testcase_03 AC 2 ms
5,636 KB
testcase_04 AC 2 ms
5,636 KB
testcase_05 AC 2 ms
5,636 KB
testcase_06 AC 2 ms
5,636 KB
testcase_07 AC 3 ms
5,636 KB
testcase_08 AC 2 ms
5,636 KB
testcase_09 AC 2 ms
5,636 KB
testcase_10 AC 2 ms
5,636 KB
testcase_11 AC 2 ms
5,636 KB
testcase_12 AC 3 ms
5,636 KB
testcase_13 AC 2 ms
5,636 KB
testcase_14 AC 2 ms
5,636 KB
testcase_15 AC 2 ms
5,636 KB
testcase_16 AC 2 ms
5,636 KB
testcase_17 AC 2 ms
5,636 KB
testcase_18 AC 2 ms
5,636 KB
testcase_19 AC 2 ms
5,636 KB
testcase_20 AC 2 ms
5,636 KB
testcase_21 AC 2 ms
5,636 KB
testcase_22 AC 7 ms
7,044 KB
testcase_23 AC 6 ms
6,788 KB
testcase_24 AC 6 ms
6,516 KB
testcase_25 AC 6 ms
6,628 KB
testcase_26 AC 7 ms
7,092 KB
testcase_27 AC 6 ms
6,836 KB
testcase_28 AC 7 ms
6,812 KB
testcase_29 AC 6 ms
6,828 KB
testcase_30 AC 6 ms
6,876 KB
testcase_31 AC 6 ms
6,728 KB
testcase_32 AC 6 ms
7,104 KB
testcase_33 AC 6 ms
6,672 KB
testcase_34 AC 7 ms
6,692 KB
testcase_35 AC 7 ms
7,184 KB
testcase_36 AC 7 ms
7,248 KB
testcase_37 AC 6 ms
6,952 KB
testcase_38 AC 6 ms
6,740 KB
testcase_39 AC 6 ms
6,976 KB
testcase_40 AC 6 ms
6,816 KB
testcase_41 AC 6 ms
6,740 KB
testcase_42 AC 5 ms
6,660 KB
testcase_43 AC 6 ms
6,660 KB
testcase_44 AC 7 ms
7,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S moddw_L(S a, const T b){
  a %= b;
  if(a < 0){
    a += b;
  }
  return a;
}
int N;
int S;
int T;
int A[100000];
int xs;
int ys;
long long x[100000];
long long y[100000];
int main(){
  int i;
  long long res = 0;
  rd(N);
  rd(S);S += (-1);
  rd(T);T += (-1);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(moddw_L((S+1),N));i!=T;i=(moddw_L((i+1),N))){
    x[xs++] = A[i];
  }
  for(i=(moddw_L((S-1),N));i!=T;i=(moddw_L((i-1),N))){
    y[ys++] = A[i];
  }
  res += A[S];
  int xr20shxY = xs/2;
  for(i=(0);i<(xr20shxY);i++){
    res += x[i];
  }
  int KrdatlYV = ys/2;
  for(i=(0);i<(KrdatlYV);i++){
    res += y[i];
  }
  if(xs%2==1 && ys%2==1){
    res +=max_L(x[xs/2], y[ys/2]);
  }
  if(xs%2==1 && ys%2==0){
    res += x[xs/2];
  }
  if(xs%2==0 && ys%2==1){
    res += y[ys/2];
  }
  res *= 2;
  for(i=(0);i<(N);i++){
    res -= A[i];
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, S, T, A[1d5];
// int xs, ys; ll x[1d5], y[1d5];
// {
//   int i;
//   ll res = 0;
//   rd(N,S--,T--,A(N));
// 
//   for(i=(S+1)%%N;i!=T;i=(i+1)%%N) x[xs++] = A[i];
//   for(i=(S-1)%%N;i!=T;i=(i-1)%%N) y[ys++] = A[i];
// 
//   res += A[S];
//   REP(i,xs/2) res += x[i];
//   REP(i,ys/2) res += y[i];
//   if(xs%2==1 && ys%2==1) res += max(x[xs/2], y[ys/2]);
//   if(xs%2==1 && ys%2==0) res += x[xs/2];
//   if(xs%2==0 && ys%2==1) res += y[ys/2];
// 
//   res *= 2;
//   rep(i,N) res -= A[i];
//   wt(res);
// }
0