結果

問題 No.2735 Demarcation
ユーザー butsurizukibutsurizuki
提出日時 2024-04-19 22:12:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 390 ms / 1,500 ms
コード長 1,344 bytes
コンパイル時間 4,195 ms
コンパイル使用メモリ 299,324 KB
実行使用メモリ 18,980 KB
最終ジャッジ日時 2024-04-19 22:12:27
合計ジャッジ時間 9,518 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 63 ms
18,904 KB
testcase_05 AC 92 ms
6,940 KB
testcase_06 AC 125 ms
15,644 KB
testcase_07 AC 390 ms
17,916 KB
testcase_08 AC 241 ms
17,412 KB
testcase_09 AC 197 ms
8,704 KB
testcase_10 AC 214 ms
10,892 KB
testcase_11 AC 34 ms
6,940 KB
testcase_12 AC 72 ms
6,944 KB
testcase_13 AC 138 ms
6,944 KB
testcase_14 AC 253 ms
13,916 KB
testcase_15 AC 155 ms
6,940 KB
testcase_16 AC 135 ms
15,848 KB
testcase_17 AC 171 ms
10,572 KB
testcase_18 AC 64 ms
6,944 KB
testcase_19 AC 210 ms
17,612 KB
testcase_20 AC 273 ms
16,704 KB
testcase_21 AC 67 ms
13,604 KB
testcase_22 AC 101 ms
18,332 KB
testcase_23 AC 50 ms
7,552 KB
testcase_24 AC 97 ms
10,736 KB
testcase_25 AC 135 ms
15,280 KB
testcase_26 AC 81 ms
14,384 KB
testcase_27 AC 67 ms
12,700 KB
testcase_28 AC 200 ms
18,736 KB
testcase_29 AC 110 ms
18,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include<bits/stdc++.h>

using namespace std;

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

long long op(long long a,long long b){
  return min(big,a+b);
}

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);

  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;
    }
    // cout << "wip\n";

    int ans=-1;
    for(int k=2;;k++){
      dp[l]=1;
      for(int i=l+1;i<=r+1;i++){
        dp[i]=0;
        set<int> st;
        for(int j=i-1;j>=l;j--){
          st.insert(a[j]);
          if(st.size()<=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