結果

問題 No.2735 Demarcation
ユーザー butsurizukibutsurizuki
提出日時 2024-04-19 22:25:05
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 1,500 ms
コード長 1,444 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 296,908 KB
実行使用メモリ 22,912 KB
最終ジャッジ日時 2024-04-19 22:25:31
合計ジャッジ時間 7,595 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 65 ms
22,752 KB
testcase_05 AC 15 ms
5,376 KB
testcase_06 AC 87 ms
18,816 KB
testcase_07 AC 118 ms
21,248 KB
testcase_08 AC 110 ms
20,932 KB
testcase_09 AC 46 ms
9,984 KB
testcase_10 AC 63 ms
12,784 KB
testcase_11 AC 24 ms
7,168 KB
testcase_12 AC 18 ms
5,376 KB
testcase_13 AC 39 ms
5,632 KB
testcase_14 AC 93 ms
16,768 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 96 ms
19,028 KB
testcase_17 AC 74 ms
12,416 KB
testcase_18 AC 31 ms
7,424 KB
testcase_19 AC 135 ms
21,448 KB
testcase_20 AC 108 ms
20,224 KB
testcase_21 AC 67 ms
16,204 KB
testcase_22 AC 101 ms
21,888 KB
testcase_23 AC 35 ms
8,832 KB
testcase_24 AC 54 ms
12,560 KB
testcase_25 AC 83 ms
18,432 KB
testcase_26 AC 78 ms
17,280 KB
testcase_27 AC 70 ms
15,104 KB
testcase_28 AC 110 ms
22,784 KB
testcase_29 AC 109 ms
22,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>

using namespace std;

long long big=(1ll<<61);

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &nx : a){cin >> nx;}

  vector<int> g(n,0);
  for(int i=1;i<n;i++){
    g[i]=g[i-1];
    if(a[i-1]==a[i]){g[i]++;}
  }

  vector<long long> dp(n+5,0);
  vector<int> mem(n+5,0);
  int clk=0;

  int q;
  cin >> q;
  while(q>0){
    q--;
    int l,r;
    long long s;
    cin >> l >> r >> s;
    l--; r--;

    int maxj=min(61,r-l);
    if((1ll<<maxj)<=s){
      cout << "-1\n"; // always <= S, so inf
      continue;
    }

    int keep=min(61,g[r]-g[l]);
    if((1ll<<keep)>s){
      cout << "0\n"; // always > S, so 0
      continue;
    }

    if(r-l>=100){
      // f >= Fib_i
      cout << "1\n";
      continue;
    }

    int ans=-1;
    for(int k=2;;k++){
      dp[l]=1;
      for(int i=l+1;i<=r+1;i++){
        dp[i]=0;
        clk++;
        int cnt=0;
        for(int j=i-1;j>=l;j--){
          if(mem[a[j]]!=clk){
            mem[a[j]]=clk;
            cnt++;
          }
          if(cnt<=k){
            dp[i]+=dp[j];
          }
          else{break;}
          if(dp[i]>s){break;}
        }
        if(dp[i]>s){
          ans=k-1;
          break;
        }
      }
      // cerr << dp[r] << "\n";
      if(ans!=-1){break;}
    }
    cout << ans << "\n";
  }
  return 0;
}
0