結果

問題 No.461 三角形はいくつ?
ユーザー imulanimulan
提出日時 2016-12-12 05:25:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,184 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 174,212 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-07 02:37:02
合計ジャッジ時間 29,954 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 4 ms
5,376 KB
testcase_05 AC 833 ms
5,376 KB
testcase_06 AC 483 ms
5,376 KB
testcase_07 AC 549 ms
5,376 KB
testcase_08 AC 383 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 117 ms
5,376 KB
testcase_11 AC 632 ms
5,376 KB
testcase_12 AC 281 ms
5,376 KB
testcase_13 AC 910 ms
5,376 KB
testcase_14 AC 892 ms
5,376 KB
testcase_15 AC 923 ms
5,376 KB
testcase_16 AC 9 ms
5,376 KB
testcase_17 AC 9 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 940 ms
5,376 KB
testcase_21 AC 949 ms
5,376 KB
testcase_22 AC 990 ms
5,376 KB
testcase_23 AC 109 ms
5,376 KB
testcase_24 AC 100 ms
5,376 KB
testcase_25 AC 1,271 ms
5,376 KB
testcase_26 AC 1,277 ms
5,376 KB
testcase_27 AC 1,267 ms
5,376 KB
testcase_28 AC 1,295 ms
5,376 KB
testcase_29 AC 1,457 ms
5,376 KB
testcase_30 AC 1,382 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 3 ms
5,376 KB
testcase_35 AC 4 ms
5,376 KB
testcase_36 AC 221 ms
5,376 KB
testcase_37 AC 210 ms
5,376 KB
testcase_38 AC 225 ms
5,376 KB
testcase_39 AC 191 ms
5,376 KB
testcase_40 AC 222 ms
5,376 KB
testcase_41 AC 217 ms
5,376 KB
testcase_42 AC 704 ms
5,376 KB
testcase_43 WA -
testcase_44 AC 707 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:86:58: warning: narrowing conversion of 'A' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   86 |                     int c_idx=lower_bound(all(l[R]),line{A,B}) - l[R].begin();
      |                                                          ^
main.cpp:86:60: warning: narrowing conversion of 'B' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   86 |                     int c_idx=lower_bound(all(l[R]),line{A,B}) - l[R].begin();
      |                                                            ^

ソースコード

diff #

#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.b*(m.a+m.b)) return 1;
    return 0;
}

inline int intersect_onedge(line m, line n)
{
    if((ll)m.a*(n.a+n.b) == (ll)n.b*(m.a+m.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 P=i, Q=(i+1)%3, R=(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;
                assert(A>=0 && B>=0);

                ll G=__gcd(A,B);
                A/=G;
                B/=G;
                if(A+B<=400000)
                {
                    int c_idx=lower_bound(all(l[R]),line{A,B}) - l[R].begin();

                    if(c_idx < l[R].size() && A==l[R][c_idx].a && B==l[R][c_idx].b) --three;
                }
            }
        }
    }

    printf("%d\n", 1+n+two+three/3);
    return 0;
}
0