結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 124 ms
6,548 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 84 ms
6,548 KB
testcase_25 AC 80 ms
6,548 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 256 ms
6,548 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]+1e17;
    for(int i=1;i<n;i++){
      if(hako>=a[i]+(i+1)*1e17){
	ok=true;
	break;
      }
      hako=a[i]+(i+1)*1e17;
    }
    if(ok){
      cout << -1 << endl;
      continue;
    }
    left=0;
    right=1e17;
    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