結果

問題 No.1623 三角形の制作
ユーザー tnakao0123tnakao0123
提出日時 2021-07-24 13:30:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,528 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 90,500 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 01:24:28
合計ジャッジ時間 3,571 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 40 ms
4,376 KB
testcase_03 AC 38 ms
4,376 KB
testcase_04 AC 38 ms
4,380 KB
testcase_05 AC 64 ms
4,376 KB
testcase_06 AC 16 ms
4,376 KB
testcase_07 AC 39 ms
4,376 KB
testcase_08 AC 17 ms
4,380 KB
testcase_09 AC 36 ms
4,376 KB
testcase_10 AC 53 ms
4,380 KB
testcase_11 AC 43 ms
4,376 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 21 ms
4,380 KB
testcase_15 AC 51 ms
4,380 KB
testcase_16 AC 52 ms
4,376 KB
testcase_17 AC 51 ms
4,376 KB
testcase_18 AC 56 ms
4,376 KB
testcase_19 AC 26 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1623.cc:  No.1623 三角形の制作 - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_L = 3000;

/* typedef */

typedef long long ll;

/* global variables */

int rcs[MAX_L + 1], gcs[MAX_L + 1], bcs[MAX_L + 1];
ll bcss[MAX_L + 1];

/* subroutines */

int readcs(int n, int cs[]) {
  int maxl = 0;
  for (int i = 0; i < n; i++) {
    int l;
    scanf("%d", &l);
    cs[l]++;
    maxl = max(maxl, l);
  }
  return maxl;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int mrl = readcs(n, rcs);
  int mgl = readcs(n, gcs);
  int mbl = readcs(n, bcs);

  for (int i = 1; i <= mrl; i++)
    bcss[i] = bcss[i - 1] + (i <= mbl ? bcs[i] : 0);
  //for (int i = 1; i <= mrl + mgl; i++) printf("bcss[%d]=%lld\n", i, bcss[i]);

  ll sum = 0;
  for (int rl = 1; rl <= mrl; rl++)
    if (rcs[rl] > 0)
      for (int gl = 1; gl <= min(mgl, rl); gl++)
	if (gcs[gl] > 0) {
	  // rl+gl>bl,gl+bl>rl,bl+rl>gl
	  // -> bl<rl+gl, bl>rl-gl, bl>gl-rl
	  int bl0 = abs(rl - gl) + 1;
	  //printf("rl=%d -> gl=%d -> bl0=%d (%lld)\n",
	  //rl, gl, bl0, bcss[rl] - bcss[bl0 - 1]);
	  sum += (ll)rcs[rl] * gcs[gl] * (bcss[rl] - bcss[bl0 - 1]);
	}

  printf("%lld\n", sum);
  return 0;
}
0