結果

問題 No.505 カードの数式2
ユーザー LayCurseLayCurse
提出日時 2017-04-21 22:39:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,861 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 144,820 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 11:25:30
合計ジャッジ時間 3,658 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 RE -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 RE -
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 RE -
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 RE -
testcase_20 AC 1 ms
4,380 KB
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline void chmin(S &a, T b){
  if(a>b){
    a=b;
  }
}
template<class S, class T> inline void chmax(S &a, T b){
  if(a<b){
    a=b;
  }
}
int A[20], N;
int main(){
  int i;
  long long n1, n2, r1, r2;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  r1 = r2 = A[0];
  for(i=1;i<N;i++){
    n1 = r1 + max(A[i], -A[i]);
    n2 = r2 + min(A[i], -A[i]);
    chmax(n1, r1 * A[i]);
    chmax(n1, r2 * A[i]);
    chmax(n1, r1 / A[i]);
    chmax(n1, r2 / A[i]);
    chmin(n2, r1 * A[i]);
    chmin(n2, r2 * A[i]);
    chmin(n2, r1 / A[i]);
    chmin(n2, r2 / A[i]);
    r1 = n1;
    r2 = n2;
  }
  wt_L(r1);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20170421-1 [beta]

// --- original code ---
// int N, A[20];
// {
//   int i;
//   ll r1, r2, n1, n2;
// 
//   reader(N,A(N));
//   r1 = r2 = A[0];
//   rep(i,1,N){
//     n1 = r1 + max(A[i], -A[i]);
//     n2 = r2 + min(A[i], -A[i]);
// 
//     n1 >?= r1 * A[i];
//     n1 >?= r2 * A[i];
//     n1 >?= r1 / A[i];
//     n1 >?= r2 / A[i];
// 
//     n2 <?= r1 * A[i];
//     n2 <?= r2 * A[i];
//     n2 <?= r1 / A[i];
//     n2 <?= r2 / A[i];
// 
//     r1 = n1;
//     r2 = n2;
//   }
// 
//   wt(r1);
// }
0