結果

問題 No.1623 三角形の制作
ユーザー simansiman
提出日時 2022-08-18 18:05:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,461 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 142,360 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-04-16 02:00:47
合計ジャッジ時間 21,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 905 ms
5,248 KB
testcase_01 AC 910 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
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 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 922 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;

  vector<int> R(N);
  vector<int> G(N);
  vector<int> B(N);
  map<int, ll> r_counter;
  map<int, ll> g_counter;
  map<int, ll> b_counter;
  for (int i = 0; i < N; ++i) {
    cin >> R[i];
    r_counter[R[i]]++;
  }
  for (int i = 0; i < N; ++i) {
    cin >> G[i];
    g_counter[G[i]]++;
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
    b_counter[B[i]]++;
  }
  sort(R.begin(), R.end());
  sort(G.begin(), G.end());
  sort(B.begin(), B.end());

  ll ans = N * N * N;
  ll dp[6010];
  memset(dp, 0, sizeof(dp));

  for (int i = 0; i < N; ++i) {
    int r = R[i];
    ll c1 = N - (int) (lower_bound(G.begin(), G.end(), r + 1) - G.begin());
    ll c2 = N - (int) (lower_bound(B.begin(), B.end(), r + 1) - B.begin());

    // fprintf(stderr, "c1: %lld, c2: %lld\n", c1, c2);
    ans -= c1 * N;
    ans -= c2 * N;
    ans += c1 * c2;
  }

  for (int v = 1; v <= 3000; ++v) {
    for (int w = 1; w <= 3000; ++w) {
      dp[v + w] += g_counter[v] * b_counter[w];
    }
  }

  for (int v = 1; v <= 3000; ++v) {
    if (r_counter[v] == 0) continue;
    for (int w = 1; w <= v; ++w) {
      if (dp[w] == 0) continue;
      ans -= dp[w];
    }
  }

  cout << ans << endl;

  return 0;
}
0