結果
| 問題 | No.461 三角形はいくつ? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-11 23:09:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,977 bytes |
| 記録 | |
| コンパイル時間 | 1,068 ms |
| コンパイル使用メモリ | 111,908 KB |
| 実行使用メモリ | 135,348 KB |
| 最終ジャッジ日時 | 2024-09-24 16:40:42 |
| 合計ジャッジ時間 | 40,910 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 4 WA * 37 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
template <class T1>
class Operators
{
public:
template <class T2>
const T1 operator+(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
ans += right;
return ans;
}
template <class T2>
const T1 operator-(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
ans -= right;
return ans;
}
template <class T2>
const T1 operator*(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
ans *= right;
return ans;
}
template <class T2>
const T1 operator/(const T2& right) const{
T1 ans = static_cast<const T1&>( *this );
ans /= right;
return ans;
}
bool operator!=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(left == right);
}
bool operator>(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return right < left;
}
bool operator<=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(right < left);
}
bool operator>=(const T1& right) const{
const T1& left = static_cast<const T1&>( *this );
return !(left < right);
}
};
class Fraction : public Operators<Fraction>
{
private:
long long n; // 分子(numerator)
long long d; // 分母(denominator)
// 約分
void reduce(){
if(d < 0){
n *= -1;
d *= -1;
}
long long a = abs(n);
long long b = d;
while(b != 0){
long long tmp = a % b;
a = b;
b = tmp;
}
n /= a;
d /= a;
}
public:
Fraction(){
n = 0;
d = 1;
}
Fraction(long long n0){
n = n0;
d = 1;
}
Fraction(long long n0, long long d0){
n = n0;
d = d0;
reduce();
}
pair<long long, long long> getValue() const{
return make_pair(n, d);
}
Fraction& operator+=(const Fraction& f){
n = n * f.d + d * f.n;
d *= f.d;
reduce();
return *this;
}
Fraction& operator-=(const Fraction& f){
n = n * f.d - d * f.n;
d *= f.d;
reduce();
return *this;
}
Fraction& operator*=(const Fraction& f){
n *= f.n;
d *= f.d;
reduce();
return *this;
}
Fraction& operator/=(const Fraction& f){
n *= f.d;
d *= f.n;
reduce();
return *this;
}
bool operator==(const Fraction& f) const{
return n == f.n && d == f.d;
}
bool operator<(const Fraction& f) const{
return n * f.d < f.n * d;
}
};
int main()
{
int n;
cin >> n;
vector<vector<Fraction> > seg(3);
for(int i=0; i<n; ++i){
int p, a, b;
cin >> p >> a >> b;
seg[p].push_back(Fraction(a, a + b));
}
vector<Fraction> v;
v.push_back(0);
for(const Fraction& a : seg[1]){
v.push_back(Fraction(1) - a);
for(const Fraction& b : seg[2]){
v.push_back(Fraction(1) - b);
Fraction f = Fraction(2) - a - b;
if(f <= 1)
v.push_back(f);
}
}
sort(v.begin(), v.end());
int ans = 0;
unsigned k = 0;
for(const Fraction& f : seg[0]){
while(k < v.size() && v[k] < f)
++ k;
ans += k;
}
ans += v.size();
cout << ans << endl;
return 0;
}