結果

問題 No.2648 [Cherry 6th Tune D] 一次元の馬
ユーザー rotti_coderrotti_coder
提出日時 2024-02-23 21:38:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 205,100 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-23 21:38:46
合計ジャッジ時間 6,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 118 ms
6,676 KB
testcase_02 AC 83 ms
6,676 KB
testcase_03 AC 83 ms
6,676 KB
testcase_04 AC 84 ms
6,676 KB
testcase_05 AC 85 ms
6,676 KB
testcase_06 AC 87 ms
6,676 KB
testcase_07 AC 84 ms
6,676 KB
testcase_08 AC 83 ms
6,676 KB
testcase_09 AC 85 ms
6,676 KB
testcase_10 AC 86 ms
6,676 KB
testcase_11 AC 84 ms
6,676 KB
testcase_12 AC 86 ms
6,676 KB
testcase_13 AC 84 ms
6,676 KB
testcase_14 AC 84 ms
6,676 KB
testcase_15 AC 84 ms
6,676 KB
testcase_16 AC 87 ms
6,676 KB
testcase_17 AC 85 ms
6,676 KB
testcase_18 AC 86 ms
6,676 KB
testcase_19 AC 84 ms
6,676 KB
testcase_20 AC 84 ms
6,676 KB
testcase_21 AC 85 ms
6,676 KB
testcase_22 AC 85 ms
6,676 KB
testcase_23 AC 83 ms
6,676 KB
testcase_24 AC 82 ms
6,676 KB
testcase_25 AC 80 ms
6,676 KB
testcase_26 AC 85 ms
6,676 KB
testcase_27 AC 85 ms
6,676 KB
testcase_28 AC 86 ms
6,676 KB
testcase_29 AC 87 ms
6,676 KB
testcase_30 AC 88 ms
6,676 KB
testcase_31 AC 86 ms
6,676 KB
testcase_32 AC 86 ms
6,676 KB
testcase_33 AC 82 ms
6,676 KB
testcase_34 AC 87 ms
6,676 KB
testcase_35 AC 250 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int t,n;
  cin >> t;
  vector<long long>a;
  bool ok;
  long long hako,left,right,mokuteki;
  for(int q=0;q<t;q++){
    a.clear();
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> hako;
      a.emplace_back(hako);
    }
    ok=true;
    for(int i=0;i<n-1;i++)if(a[i]>=a[i+1])ok=false;
    if(ok){
      cout << 0 << endl;
      continue;
    }
    ok=false;
    hako=a[0]+1e9+100;
    for(int i=1;i<n;i++){
      if(hako>=a[i]+(i+1)*(1e9+100)){
	ok=true;
	break;
      }
      hako=a[i]+(i+1)*(1e9+100);
    }
    if(ok){
      cout << -1 << endl;
      continue;
    }
    left=0;
    right=1e9+100;
    while(left+1!=right){
      mokuteki=(left+right)/2;
      hako=a[0]+mokuteki;
      ok=true;
      for(int i=1;i<n;i++){
	if(hako>=a[i]+(i+1)*mokuteki){
	  ok=false;
	  break;
	}
	hako=a[i]+(i+1)*mokuteki;
      }
      if(ok)right=mokuteki;
      else left=mokuteki;
    }
    cout << right << endl;
  }
  return 0;
}
0