結果

問題 No.1079 まお
ユーザー 0w10w1
提出日時 2020-07-12 18:52:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,210 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 214,992 KB
実行使用メモリ 25,204 KB
最終ジャッジ日時 2023-08-05 22:37:51
合計ジャッジ時間 10,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 137 ms
12,520 KB
testcase_13 AC 110 ms
10,188 KB
testcase_14 AC 258 ms
17,160 KB
testcase_15 AC 221 ms
14,904 KB
testcase_16 AC 198 ms
13,668 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 345 ms
20,184 KB
testcase_23 AC 355 ms
19,672 KB
testcase_24 AC 399 ms
21,992 KB
testcase_25 AC 454 ms
24,664 KB
testcase_26 AC 496 ms
25,204 KB
testcase_27 AC 37 ms
4,380 KB
testcase_28 AC 106 ms
14,508 KB
testcase_29 AC 137 ms
14,336 KB
testcase_30 AC 138 ms
14,432 KB
testcase_31 AC 46 ms
4,380 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