AtCoder Regular Contest 042

Submission #1068861

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 > >;

int main() {
  ll x, y;
  scanf("%lld %lld", &x, &y);
  int n;
  scanf("%d", &n);
  vll x_(n), y_(n);
  rep (i, n) {
    scanf("%lld %lld", &x_[i], &y_[i]);
  }
  double ans = 1000;
  rep (i, n) {
    ll x0 = x_[i];
    ll y0 = y_[i];
    ll x1 = x_[(i+1)%n];
    ll y1 = y_[(i+1)%n];

    ll la2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
    ll lb2 = (x - x1) * (x - x1) + (y - y1) * (y - y1);
    ll lc2 = (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);

    if (la2 + lc2 - lb2 < 0 || lb2 + lc2 - la2 < 0) {
      ans = min(ans, sqrt(la2));
      ans = min(ans, sqrt(lb2));
    }

    double a = y1 - y0;
    double b = x0 - x1;
    double c = x0 * (y0 - y1) + y0 * (x1 - x0);

    ans = min(ans, abs(a * x + b * y + c) / sqrt(a*a + b*b));
  }
  printf("%.9f\n", ans);

  return 0;
}

Submission

Task問題 B - アリの高橋くん
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++14 (Clang++ 3.4)
Status状態 AC
Score得点 100
Source lengthソースコード長 1721 Byte
File nameファイル名
Exec time実行時間 19 ms
Memory usageメモリ使用量 928 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
All 100 / 100 sample_01.txt,sample_02.txt,sample_03.txt,subtask1_00.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask1_13.txt,subtask1_14.txt,subtask1_15.txt,subtask1_16.txt,subtask1_17.txt,subtask1_18.txt,subtask1_19.txt,subtask1_20.txt,subtask1_21.txt,subtask1_22.txt,subtask1_23.txt,subtask1_24.txt,subtask1_25.txt,subtask1_26.txt,subtask1_27.txt,subtask1_28.txt,subtask1_29.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 18 ms 924 KB
sample_02.txt AC 17 ms 928 KB
sample_03.txt AC 18 ms 800 KB
subtask1_00.txt AC 18 ms 920 KB
subtask1_01.txt AC 18 ms 916 KB
subtask1_02.txt AC 18 ms 796 KB
subtask1_03.txt AC 19 ms 788 KB
subtask1_04.txt AC 19 ms 796 KB
subtask1_05.txt AC 18 ms 920 KB
subtask1_06.txt AC 18 ms 924 KB
subtask1_07.txt AC 18 ms 928 KB
subtask1_08.txt AC 19 ms 792 KB
subtask1_09.txt AC 18 ms 928 KB
subtask1_10.txt AC 17 ms 792 KB
subtask1_11.txt AC 18 ms 920 KB
subtask1_12.txt AC 18 ms 924 KB
subtask1_13.txt AC 19 ms 796 KB
subtask1_14.txt AC 17 ms 916 KB
subtask1_15.txt AC 18 ms 928 KB
subtask1_16.txt AC 18 ms 928 KB
subtask1_17.txt AC 19 ms 796 KB
subtask1_18.txt AC 19 ms 924 KB
subtask1_19.txt AC 19 ms 796 KB
subtask1_20.txt AC 18 ms 796 KB
subtask1_21.txt AC 18 ms 928 KB
subtask1_22.txt AC 19 ms 924 KB
subtask1_23.txt AC 18 ms 800 KB
subtask1_24.txt AC 17 ms 800 KB
subtask1_25.txt AC 18 ms 800 KB
subtask1_26.txt AC 17 ms 924 KB
subtask1_27.txt AC 18 ms 796 KB
subtask1_28.txt AC 17 ms 796 KB
subtask1_29.txt AC 17 ms 920 KB