結果

問題 No.1079 まお
ユーザー 0w10w1
提出日時 2020-07-12 18:52:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 2,400 ms
コンパイル使用メモリ 212,624 KB
実行使用メモリ 25,600 KB
最終ジャッジ日時 2024-04-23 18:59:26
合計ジャッジ時間 7,927 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
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 AC 108 ms
12,928 KB
testcase_13 AC 94 ms
10,336 KB
testcase_14 AC 176 ms
17,232 KB
testcase_15 AC 154 ms
15,136 KB
testcase_16 AC 149 ms
14,000 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 240 ms
20,408 KB
testcase_23 AC 233 ms
19,840 KB
testcase_24 AC 294 ms
22,272 KB
testcase_25 AC 325 ms
24,704 KB
testcase_26 AC 325 ms
25,600 KB
testcase_27 AC 39 ms
6,940 KB
testcase_28 AC 95 ms
14,596 KB
testcase_29 AC 121 ms
14,592 KB
testcase_30 AC 121 ms
14,592 KB
testcase_31 AC 46 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  /* ios::sync_with_stdio(false); */

  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  function<int64_t(int, int)> dvcq = [&](int l, int r) {
    if (r - l < 1) return (int64_t) 0;

    int64_t res = 0;
    map<int, int> cnt;
    for (int i = l; i < r; ++i) ++cnt[A[i]];

    if (cnt.begin()->second < 2) {
      map<int, int64_t> sum;
      for (int i = l; i < r; ++i) sum[A[i]] += i + 1;
      for (int i = l; i < r; ++i) {
        if (A[i] <= K) res += sum[K - A[i]] - (int64_t) i * cnt[K - A[i]];
        --cnt[A[i]];
        sum[A[i]] -= i + 1;
      }
    } else {
      int i = l;
      int j = i;
      while (j < r && A[j] != cnt.begin()->first) ++j;
      for (++j; j < r && A[j] != cnt.begin()->first; ++j) ;
      res += dvcq(i, j);
      while (true) {
        while (i < r && A[i] != cnt.begin()->first) ++i;
        if (++i >= r) break;
        res -= dvcq(i, j);
        for (++j; j < r && A[j] != cnt.begin()->first; ++j) ;
        if (j > r) j = r;
        res += dvcq(i, j);
        if (j == r) break;
      }
    }

    return res;
  };

  cout << dvcq(0, N) << endl;

  return 0;
}
0