AtCoder Beginner Contest 033

Submission #1111491

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;
typedef pair<double, int> pdi;

#define EPS 1e-14

int main() {
  int n;
  scanf("%d", &n);
  vi x(n), y(n);
  rep (i, n) {
    scanf("%d %d", &x[i], &y[i]);
  }
  ll ei, cho, don, devnull;
  ei = cho = don = devnull = 0;
  rep (i, n) {
    vector<double> theta;
    theta.reserve(n);
    rep (j, n) {
      if (i == j) {
        continue;
      }
      int dx = x[j] - x[i];
      int dy = y[j] - y[i];
      double tj = atan2(dy, dx);
      theta.push_back(tj);
    }
    sort(all(theta));
    vector<double> ar;
    ar.reserve(3 * n);
    rep (j, n-1) {
      ar.push_back(theta[j] - 2*M_PI);
      ar.push_back(theta[j]);
      ar.push_back(theta[j] + 2*M_PI);
    }
    sort(all(ar));
    int sz = (int)ar.size();
    vvi tpa(n-1, vi(10, 0));
    rep (k, 5) {
      tpa[0][2*k] = lower_bound(all(ar), theta[0] + (k-2) * M_PI/2 - EPS) - begin(ar);
      tpa[0][2*k+1] = upper_bound(all(ar), theta[0] + (k-2) * M_PI/2 + EPS) - begin(ar);
    }
    FOR (j, 1, n-1) {
      tpa[j][0] = tpa[j-1][0];
      while (ar[tpa[j][0]] < theta[j] + (-2) * M_PI/2 - EPS && tpa[j][0] < sz-1) {
        tpa[j][0] += 1;
      }
      tpa[j][1] = max(tpa[j-1][1], tpa[j][0]);
      while (ar[tpa[j][1]] <= theta[j] + (-2) * M_PI/2 + EPS && tpa[j][1] < sz-1) {
        tpa[j][1] += 1;
      }
      FOR (k, 1, 5) {
        tpa[j][2*k] = max(tpa[j-1][2*k], tpa[j][2*k-1]);
        while (ar[tpa[j][2*k]] < theta[j] + (k-2) * M_PI/2 - EPS && tpa[j][2*k] < sz-1) {
          tpa[j][2*k] += 1;
        }
        tpa[j][2*k+1] = max(tpa[j-1][2*k+1], tpa[j][2*k]);
        while (ar[tpa[j][2*k+1]] <= theta[j] + (k-2) * M_PI/2 + EPS && tpa[j][2*k+1] < sz-1) {
          tpa[j][2*k+1] += 1;
        }
      }
    }
    rep (j, n-1) {
      don += tpa[j][2] - tpa[j][1];
      cho += tpa[j][3] - tpa[j][2];
      devnull += tpa[j][5] - tpa[j][4] - 1;
      cho += tpa[j][7] - tpa[j][6];
      don += tpa[j][8] - tpa[j][7];
    }
  }
  cho /= 2;
  don /= 2;
  devnull /= 2;
  ei = (ll)n * (n-1) * (n-2) / 6 - cho - don - devnull;
  printf("%lld %lld %lld\n", ei, cho, don);
  return 0;
}

Submission

Task問題 D - 三角形の分類
User nameユーザ名 gosenoku
Created time投稿日時
Language言語 C++14 (Clang 3.8.0)
Status状態 AC
Score得点 100
Source lengthソースコード長 3034 Byte
File nameファイル名
Exec time実行時間 1229 ms
Memory usageメモリ使用量 512 KB

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
subtask01 30 / 30 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 70 / 70 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
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 11 ms 256 KB
02-01.txt AC 44 ms 256 KB
02-02.txt AC 43 ms 256 KB
02-03.txt AC 141 ms 384 KB
02-04.txt AC 142 ms 384 KB
02-05.txt AC 142 ms 384 KB
02-06.txt AC 289 ms 384 KB
02-07.txt AC 289 ms 384 KB
02-08.txt AC 290 ms 384 KB
02-09.txt AC 289 ms 384 KB
02-10.txt AC 289 ms 384 KB
02-11.txt AC 289 ms 384 KB
02-12.txt AC 290 ms 384 KB
02-13.txt AC 1226 ms 512 KB
02-14.txt AC 1227 ms 512 KB
02-15.txt AC 1227 ms 512 KB
02-16.txt AC 1227 ms 512 KB
02-17.txt AC 1225 ms 512 KB
02-18.txt AC 1228 ms 512 KB
02-19.txt AC 1225 ms 512 KB
02-handmade00.txt AC 571 ms 384 KB
02-handmade01.txt AC 1229 ms 512 KB
02-handmade02.txt AC 671 ms 384 KB
02-handmade03.txt AC 1220 ms 512 KB
02-handmade04.txt AC 1227 ms 512 KB
02-handmade05.txt AC 1227 ms 512 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB