結果
問題 | No.1623 三角形の制作 |
ユーザー |
![]() |
提出日時 | 2021-07-24 13:30:25 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 1,528 bytes |
コンパイル時間 | 1,009 ms |
コンパイル使用メモリ | 93,452 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 19:03:49 |
合計ジャッジ時間 | 2,893 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
/* -*- 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; }