結果
問題 |
No.3128 Isosceles Triangle
|
ユーザー |
![]() |
提出日時 | 2025-04-28 14:29:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,500 ms |
コード長 | 970 bytes |
コンパイル時間 | 618 ms |
コンパイル使用メモリ | 44,028 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-04-28 14:29:33 |
合計ジャッジ時間 | 4,763 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:31:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | for (int i = 0; i < n; i++) scanf("%d", as + i); | ~~~~~^~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3128.cc: No.3128 Isosceles Triangle - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 300000; /* typedef */ using ll = long long; /* global variables */ int as[MAX_N], cs[MAX_N]; ll css[MAX_N + 1]; /* subroutines */ /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", as + i); sort(as, as + n); int m = 0; for (int i = 0; i < n;) { int j = i; while (i < n && as[j] == as[i]) i++; as[m] = as[j], cs[m] = i - j, m++; } for (int i = 0; i < m; i++) css[i + 1] = css[i] + cs[i]; //for (int i = 0; i < m; i++) printf(" %d,%d", as[i], cs[i]); putchar('\n'); ll sum = 0; for (int i = 0; i < m; i++) if (cs[i] >= 2) { ll nc2 = (ll)cs[i] * (cs[i] - 1) / 2; int j = lower_bound(as, as + m, as[i] * 2) - as; sum += nc2 * (css[j] - cs[i]); } printf("%lld\n", sum); return 0; }