結果
| 問題 | No.461 三角形はいくつ? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-12 06:20:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,191 bytes |
| 記録 | |
| コンパイル時間 | 1,851 ms |
| コンパイル使用メモリ | 174,840 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 15:17:29 |
| 合計ジャッジ時間 | 26,406 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 32 RE * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
typedef pair<int,int> pi;
struct line
{
int a,b;
bool operator<(const line& t) const {
return (ll)a*(t.a+t.b) < (ll)t.a*(a+b);
}
};
inline int intersect_inside(line m, line n)
{
if((ll)m.a*(n.a+n.b) + (ll)n.a*(m.a+m.b) > (ll)(m.a+m.b)*(n.a+n.b)) return 1;
return 0;
}
inline int intersect_onedge(line m, line n)
{
if((ll)m.a*(n.a+n.b) + (ll)n.a*(m.a+m.b) == (ll)(m.a+m.b)*(n.a+n.b)) return 1;
return 0;
}
int main()
{
int n;
scanf(" %d", &n);
vector<line> l[3];
rep(i,n)
{
int p,a,b;
scanf(" %d %d %d", &p, &a, &b);
int G=__gcd(a,b);
a/=G;
b/=G;
l[p].pb(line{a,b});
}
rep(i,3) sort(all(l[i]));
int two=0,three=0;
rep(i,3)
{
int R=i, P=(i+1)%3, Q=(i+2)%3;
rep(j,l[P].size())rep(k,l[Q].size())
{
line pp=l[P][j], qq=l[Q][k];
two+=intersect_inside(pp,qq);
if(intersect_inside(pp,qq) || intersect_onedge(pp,qq))
{
line base = max(line{pp.b,pp.a}, line{qq.b,qq.a});
// printf("base (%d, %d)\n", base.a, base.b);
int idx = lower_bound(all(l[R]),base) - l[R].begin();
three += (int)l[R].size()-idx;
// printf("idx = %d : (%d, %d)\n", idx,l[R][idx].a, l[R][idx].b);
ll D=(ll)pp.a*(qq.a+qq.b) + (ll)qq.a*(pp.a+pp.b);
ll C=(ll)(pp.a+pp.b)*(qq.a+qq.b);
ll A=2*C-D, B=D-C;
ll G=__gcd(A,B);
A/=G;
B/=G;
if(A>0 && B>0 && A+B<=400000)
{
line lb = *lower_bound(all(l[R]),line{(int)A,(int)B});
if(lb.a==A && lb.b==B) --three;
}
}
}
}
assert(three%3==0);
printf("%d\n", 1+n+two+three/3);
return 0;
}