結果

問題 No.461 三角形はいくつ?
ユーザー char134217728char134217728
提出日時 2019-02-19 22:20:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 766 ms / 5,000 ms
コード長 1,400 bytes
コンパイル時間 2,191 ms
コンパイル使用メモリ 181,392 KB
実行使用メモリ 113,392 KB
最終ジャッジ日時 2024-04-21 00:07:30
合計ジャッジ時間 11,581 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 328 ms
52,672 KB
testcase_06 AC 184 ms
31,296 KB
testcase_07 AC 214 ms
35,984 KB
testcase_08 AC 151 ms
28,100 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 46 ms
10,160 KB
testcase_11 AC 257 ms
52,664 KB
testcase_12 AC 105 ms
19,884 KB
testcase_13 AC 378 ms
58,032 KB
testcase_14 AC 354 ms
55,120 KB
testcase_15 AC 380 ms
58,824 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 766 ms
112,608 KB
testcase_19 AC 754 ms
113,392 KB
testcase_20 AC 363 ms
56,396 KB
testcase_21 AC 376 ms
59,716 KB
testcase_22 AC 380 ms
58,052 KB
testcase_23 AC 65 ms
15,848 KB
testcase_24 AC 62 ms
15,944 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 5 ms
5,376 KB
testcase_28 AC 5 ms
5,376 KB
testcase_29 AC 144 ms
28,004 KB
testcase_30 AC 67 ms
15,764 KB
testcase_31 AC 283 ms
52,668 KB
testcase_32 AC 371 ms
62,544 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 4 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 125 ms
28,104 KB
testcase_37 AC 124 ms
27,972 KB
testcase_38 AC 128 ms
28,100 KB
testcase_39 AC 109 ms
19,276 KB
testcase_40 AC 127 ms
28,104 KB
testcase_41 AC 132 ms
28,004 KB
testcase_42 AC 398 ms
64,328 KB
testcase_43 AC 409 ms
68,292 KB
testcase_44 AC 388 ms
62,660 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 | main(){
      | ^~~~

ソースコード

diff #

#include <bits/stdc++.h>
#include "unistd.h"
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(a) (a.begin()),(a.end())

typedef __int128_t ll;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;

int n;
V<pll> v[3], c, s;
function<bool (const pll&a, const pll&b)> _less = [](const pll&a, const pll&b){
  return a.fi*b.se < b.fi*a.se;
};
pll _plus(const pll&a, const pll&b){
  return pll(a.fi*b.se+b.fi*a.se, a.se*b.se);
};
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    int p, a, b;
    cin >> p >> a >> b;
    v[p].pb(pll(a, a+b));
  }
  sort(v, v+3, [](const V<pll>&a, const V<pll>&b){return sz(a)<sz(b);});
  FOR(i, 0, 3){
    sort(all(v[i]), _less);
    v[i].pb(pll(1,1));
  }
  reverse(all(v[1]));
  for(pll p0:v[0]) for(pll p1:v[1]){
    pll p = _plus(p0, p1);
    if(p.fi < p.se) break;
    p.fi = p.se*2-p.fi;
    c.pb(p);
    p = _less(p0, p1) ? p0 : p1;
    p.fi = p.se-p.fi;
    s.pb(p);
  }
  sort(all(c), _less);
  sort(all(s), _less);
  ll ans = 0;
  for(pll p:v[2]){
    ans += distance(
        s.begin(),
        upper_bound(all(s), p, _less)
        );
    ans -= distance(
        lower_bound(all(c), p, _less),
        upper_bound(all(c), p, _less)
        );
  }
  cout << (long long)ans << endl;
}
0