結果

問題 No.2735 Demarcation
ユーザー butsurizukibutsurizuki
提出日時 2024-04-19 22:22:54
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 1,500 ms
コード長 1,362 bytes
コンパイル時間 4,599 ms
コンパイル使用メモリ 294,808 KB
実行使用メモリ 22,812 KB
最終ジャッジ日時 2024-04-19 22:23:03
合計ジャッジ時間 8,043 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 70 ms
22,812 KB
testcase_05 AC 16 ms
5,376 KB
testcase_06 AC 99 ms
18,688 KB
testcase_07 AC 154 ms
21,376 KB
testcase_08 AC 129 ms
20,864 KB
testcase_09 AC 52 ms
10,112 KB
testcase_10 AC 70 ms
12,800 KB
testcase_11 AC 26 ms
7,168 KB
testcase_12 AC 20 ms
5,376 KB
testcase_13 AC 43 ms
5,632 KB
testcase_14 AC 102 ms
16,640 KB
testcase_15 AC 23 ms
5,376 KB
testcase_16 AC 105 ms
18,944 KB
testcase_17 AC 76 ms
12,544 KB
testcase_18 AC 33 ms
7,296 KB
testcase_19 AC 122 ms
21,248 KB
testcase_20 AC 121 ms
20,096 KB
testcase_21 AC 75 ms
16,128 KB
testcase_22 AC 112 ms
21,888 KB
testcase_23 AC 37 ms
8,704 KB
testcase_24 AC 65 ms
12,544 KB
testcase_25 AC 101 ms
18,432 KB
testcase_26 AC 85 ms
17,152 KB
testcase_27 AC 76 ms
14,848 KB
testcase_28 AC 135 ms
22,784 KB
testcase_29 AC 122 ms
22,784 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;
    }

    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