結果

問題 No.1623 三角形の制作
ユーザー simansiman
提出日時 2022-08-18 18:08:27
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 923 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 141,868 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2024-04-16 02:04:29
合計ジャッジ時間 21,029 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 904 ms
5,248 KB
testcase_01 AC 902 ms
5,376 KB
testcase_02 AC 811 ms
5,376 KB
testcase_03 AC 812 ms
5,376 KB
testcase_04 AC 829 ms
5,376 KB
testcase_05 AC 923 ms
6,144 KB
testcase_06 AC 740 ms
5,376 KB
testcase_07 AC 817 ms
5,376 KB
testcase_08 AC 718 ms
5,376 KB
testcase_09 AC 806 ms
5,376 KB
testcase_10 AC 876 ms
5,760 KB
testcase_11 AC 826 ms
5,376 KB
testcase_12 AC 743 ms
5,376 KB
testcase_13 AC 758 ms
5,376 KB
testcase_14 AC 755 ms
5,376 KB
testcase_15 AC 854 ms
6,144 KB
testcase_16 AC 851 ms
6,016 KB
testcase_17 AC 894 ms
6,144 KB
testcase_18 AC 876 ms
6,016 KB
testcase_19 AC 809 ms
5,376 KB
testcase_20 AC 918 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() {
  ll 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 - (ll) (lower_bound(G.begin(), G.end(), r + 1) - G.begin());
    ll c2 = N - (ll) (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 -= r_counter[v] * dp[w];
    }
  }

  cout << ans << endl;

  return 0;
}
0