Submission #3418829


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

   typedef long long ll;

   const double EPS = (1e-14);
   const int INF =(1e9);
   const double PI = (acos(-1));
   const ll MOD = (ll(1e9) + 7);

   #define REP(i, n) for(int i = 0; i < (int)(n); i++)
   #define FOR(i, a, b) for (int i = (a); i < (b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((int)(x).size())


   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

   int dx[4]={1,0,-1,0};
   int dy[4]={0,1,0,-1};

double arg(ll x, ll y){
    //(x, y)の偏角を計算 0 ~ 2 * PI ラジアン
    if (y >= 0) return atan2(x, y);
    else return atan2(x, y) + 2 * PI;
}

pair<ll, ll> tri_type(vector<double> a){
    //a0, a1, a2, ..., a(n-1) : argments
    //原点から見て直角がいくつ, 鈍角がいくつあるか数える
    //return <right, dull>
    SORT(a);
    ll n = a.size();
    REP(i, n){
        //偏角の列aを2周させておく -> 2分探索の区間を指定しやすい
        a.push_back(a[i] + 2 * PI);
    }
    ll right = 0, dull = 0;
    REP(i, n){
        auto low1 = lower_bound(ALL(a), a[i] + PI / 2 - EPS);
        auto up1 = upper_bound(ALL(a), a[i] + PI / 2 + EPS);
        auto low2 = lower_bound(ALL(a), a[i] + PI * 3 / 2 - EPS);
        auto up2 = upper_bound(ALL(a), a[i] + PI * 3 / 2 + EPS);
        right += (up1 - low1) + (up2 - low2);
        dull += (low2 - up1); 
    }
    right /= 2;
    dull /= 2;
    return make_pair(right, dull);
}

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   ll n; cin >> n;
   vector<vector<ll>> p;
   REP(i, n){
       ll xi, yi;
       cin >> xi >> yi;
       p.push_back({xi, yi});
   }
   ll right = 0, dull = 0, acute = 0; // それぞれ三角形のタイプ別の個数
   REP(i, n){
       vector<double> a;
       REP(j, n){
           if (j != i){
               a.push_back(atan2(p[j][1] - p[i][1], p[j][0] - p[i][0]));
           }
       }
       //これでa = (p[i]を原点として見たときの偏角の列)となった
       right += tri_type(a).first;
       dull += tri_type(a).second;
   }
   acute = n * (n - 1) * (n - 2) / 6 - right - dull;
   cout << acute <<' ' << right << ' ' << dull << endl;
}

Submission Info

Submission Time
Task D - 三角形の分類
User genkinanodesu
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2427 Byte
Status AC
Exec Time 1618 ms
Memory 512 KB

Judge Result

Set Name sample subtask01 subtask02
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 2
AC × 28
AC × 56
Set Name Test Cases
sample sample-01.txt, sample-02.txt
subtask01 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-handmade00.txt, 01-handmade01.txt, 01-handmade02.txt, 01-handmade03.txt, 01-handmade04.txt, 01-handmade05.txt, sample-01.txt, sample-02.txt
subtask02 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-handmade00.txt, 01-handmade01.txt, 01-handmade02.txt, 01-handmade03.txt, 01-handmade04.txt, 01-handmade05.txt, 02-00.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-handmade00.txt, 02-handmade01.txt, 02-handmade02.txt, 02-handmade03.txt, 02-handmade04.txt, 02-handmade05.txt, sample-01.txt, sample-02.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-00.txt AC 1 ms 256 KB
01-01.txt AC 1 ms 256 KB
01-02.txt AC 1 ms 256 KB
01-03.txt AC 1 ms 256 KB
01-04.txt AC 1 ms 256 KB
01-05.txt AC 2 ms 256 KB
01-06.txt AC 2 ms 256 KB
01-07.txt AC 4 ms 256 KB
01-08.txt AC 4 ms 256 KB
01-09.txt AC 4 ms 256 KB
01-10.txt AC 4 ms 256 KB
01-11.txt AC 4 ms 256 KB
01-12.txt AC 4 ms 256 KB
01-13.txt AC 4 ms 256 KB
01-14.txt AC 4 ms 256 KB
01-15.txt AC 4 ms 256 KB
01-16.txt AC 4 ms 256 KB
01-17.txt AC 4 ms 256 KB
01-18.txt AC 4 ms 256 KB
01-19.txt AC 4 ms 256 KB
01-handmade00.txt AC 2 ms 256 KB
01-handmade01.txt AC 4 ms 256 KB
01-handmade02.txt AC 2 ms 256 KB
01-handmade03.txt AC 4 ms 256 KB
01-handmade04.txt AC 4 ms 256 KB
01-handmade05.txt AC 4 ms 256 KB
02-00.txt AC 14 ms 256 KB
02-01.txt AC 58 ms 256 KB
02-02.txt AC 58 ms 256 KB
02-03.txt AC 184 ms 384 KB
02-04.txt AC 184 ms 384 KB
02-05.txt AC 184 ms 384 KB
02-06.txt AC 386 ms 384 KB
02-07.txt AC 385 ms 384 KB
02-08.txt AC 387 ms 384 KB
02-09.txt AC 384 ms 384 KB
02-10.txt AC 385 ms 384 KB
02-11.txt AC 390 ms 384 KB
02-12.txt AC 386 ms 384 KB
02-13.txt AC 1607 ms 384 KB
02-14.txt AC 1611 ms 384 KB
02-15.txt AC 1608 ms 384 KB
02-16.txt AC 1613 ms 384 KB
02-17.txt AC 1608 ms 384 KB
02-18.txt AC 1613 ms 384 KB
02-19.txt AC 1605 ms 512 KB
02-handmade00.txt AC 746 ms 384 KB
02-handmade01.txt AC 1611 ms 384 KB
02-handmade02.txt AC 888 ms 384 KB
02-handmade03.txt AC 1610 ms 384 KB
02-handmade04.txt AC 1618 ms 384 KB
02-handmade05.txt AC 1608 ms 384 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB