結果

問題 No.461 三角形はいくつ?
ユーザー koba-e964koba-e964
提出日時 2016-12-12 11:57:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,202 bytes
コンパイル時間 1,988 ms
コンパイル使用メモリ 96,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-07 03:06:08
合計ジャッジ時間 52,002 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 7 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 8 ms
5,376 KB
testcase_34 AC 7 ms
5,376 KB
testcase_35 AC 5 ms
5,376 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
const ll mod = 1e9 + 7;

ll gcd(ll x, ll y) {
  return y == 0 ? x : gcd(y, x % y);
}

PL add(PL x, PL y) {
  PI w = PI(x.first * y.second + x.second * y.first,
		x.second * y.second);
  ll g = gcd(w.first, w.second);
  w.first /= g;
  w.second /= g;
  return w;
}

PL neg(PL x) { return PL(- x.first, x.second); }

bool fr_le(PL x, PL y) {
  return x.first * y.second <= y.first * x.second;
}
bool fr_lt(PL x, PL y) {
  return x.first * y.second < y.first * x.second;
}
int main(void){
  int n;
  cin >> n;
  vector<PL> pool[3];
  REP(i, 0, 3) {
    pool[i].push_back(PL(0, 1));
  }
  REP(i, 0, n) {
    int p, a, b;
    cin >> p >> a >> b;
    int g = __gcd(a, b);
    a /= g;
    b /= g;
    pool[p].push_back(PL(b, a + b));
  }
  ll tot = 0;
  sort(pool[2].begin(), pool[2].end(), fr_lt);
  REP(i, 0, pool[0].size()) {
    REP(j, 0, pool[1].size()) {
      PL u = pool[0][i];
      PL v = pool[1][j];
      if (not fr_le(add(u, v), PL(1, 1))) {
	continue;
      }
      PL ma = u;
      if (fr_le(u, v)) { ma = v; }
      // find #{x | x + u <= 1 && x + v <= 1 && x + u + v != 1}
      PL x_ma = add(PL(1, 1), neg(ma));
      int idx = upper_bound(pool[2].begin(), pool[2].end(), x_ma, fr_lt)
	- pool[2].begin();
      tot += idx;
      PL excl = add(PL(1, 1), neg(add(u, v)));
      {
	int idx1 = upper_bound(pool[2].begin(), pool[2].end(), excl, fr_lt)
	- pool[2].begin();
	int idx2 = lower_bound(pool[2].begin(), pool[2].end(), excl, fr_lt)
	- pool[2].begin();
	assert (idx1 - idx2 <= 1);
	assert (idx1 >= idx2);
	tot -= idx1 - idx2;
      }
    }
  }
  cout << tot << endl;
}
0