結果
問題 | No.96 圏外です。 |
ユーザー | 0w1 |
提出日時 | 2016-12-05 12:50:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,778 bytes |
コンパイル時間 | 2,444 ms |
コンパイル使用メモリ | 186,844 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-11-27 21:14:46 |
合計ジャッジ時間 | 73,827 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
11,424 KB |
testcase_01 | AC | 2 ms
11,424 KB |
testcase_02 | AC | 2 ms
11,428 KB |
testcase_03 | AC | 2 ms
11,168 KB |
testcase_04 | AC | 6 ms
11,300 KB |
testcase_05 | AC | 14 ms
11,296 KB |
testcase_06 | AC | 29 ms
6,820 KB |
testcase_07 | AC | 62 ms
6,820 KB |
testcase_08 | AC | 118 ms
6,816 KB |
testcase_09 | AC | 215 ms
6,816 KB |
testcase_10 | AC | 380 ms
6,820 KB |
testcase_11 | AC | 636 ms
7,168 KB |
testcase_12 | AC | 1,008 ms
8,704 KB |
testcase_13 | AC | 1,572 ms
7,296 KB |
testcase_14 | AC | 2,372 ms
10,112 KB |
testcase_15 | AC | 3,518 ms
7,936 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 3,552 ms
13,056 KB |
testcase_26 | TLE | - |
testcase_27 | AC | 4,366 ms
18,688 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair< int, int > pii; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef vector< pii > vp; typedef vector< vp > vvp; typedef vector< string > vs; typedef vector< double > vd; typedef vector< vd > vvd; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; int N; vi X, Y; void init(){ cin >> N; X = Y = vi( N ); for( int i = 0; i < N; ++i ) cin >> X[ i ] >> Y[ i ]; } struct dsu{ vi fa; dsu( int sz ){ fa = vi( sz ); for( int i = 0; i < sz; ++i ) fa[ i ] = i; } int find( int x ){ return fa[ x ] == x ? x : fa[ x ] = find( fa[ x ] ); } int merge( int a, int b ){ int x = find( a ); int y = find( b ); if( x == y ) return 0; fa[ x ] = y; return 1; } }; map< int, vi > group; int eu_dis2( int a, int b, int x, int y ){ int dx = a - x; int dy = b - y; return dx * dx + dy * dy; } double eu_dis( int a, int b, int x, int y ){ double dx = a - x; double dy = b - y; return sqrt( dx * dx + dy * dy ); } void preprocess(){ dsu *uf = new dsu( N ); for( int i = 0; i < N; ++i ) for( int j = i + 1; j < N; ++j ) if( eu_dis2( X[ i ], Y[ i ], X[ j ], Y[ j ] ) <= 100 ) uf->merge( i, j ); for( int i = 0; i < N; ++i ) group[ uf->find( i ) ].emplace_back( i ); } void solve(){ double ans = N == 0 ? 1.0 : 2.0; for( auto it = group.begin(); it != group.end(); ++it ){ sort( ( it->second ).begin(), ( it->second ).end(), [ & ]( int i, int j ){ return X[ i ] != X[ j ] ? X[ i ] < X[ j ] : Y[ i ] < Y[ j ]; } ); vector< int > stk; function< double ( double, double, double, double ) > cross = [ & ]( double x1, double y1, double x2, double y2 ){ return x1 * y2 - y1 * x2; }; for( int i = 0; i < ( it->second ).size(); ++i ){ while( stk.size() >= 2 ){ int s = stk.size(); double dx1 = X[ stk[ s - 1 ] ] - X[ stk[ s - 2 ] ]; double dy1 = Y[ stk[ s - 1 ] ] - Y[ stk[ s - 2 ] ]; double dx2 = X[ ( it->second )[ i ] ] - X[ stk[ s - 2 ] ]; double dy2 = Y[ ( it->second )[ i ] ] - Y[ stk[ s - 2 ] ]; if( cross( dx1, dy1, dx2, dy2 ) <= 0.0 ) stk.pop_back(); else break; } stk.emplace_back( ( it->second )[ i ] ); } int h = stk.size(); for( int i = ( int ) ( it->second ).size() - 2; i >= 0; --i ){ while( stk.size() > h ){ int s = stk.size(); double dx1 = X[ stk[ s - 1 ] ] - X[ stk[ s - 2 ] ]; double dy1 = Y[ stk[ s - 1 ] ] - Y[ stk[ s - 2 ] ]; double dx2 = X[ ( it->second )[ i ] ] - X[ stk[ s - 2 ] ]; double dy2 = Y[ ( it->second )[ i ] ] - Y[ stk[ s - 2 ] ]; if( cross( dx1, dy1, dx2, dy2 ) <= 0.0 ) stk.pop_back(); else break; } stk.emplace_back( ( it->second )[ i ] ); } stk.pop_back(); // start h = stk.size(); for( int i = 0; i < h; ++i ) stk.emplace_back( stk[ i ] ); for( int i = 0, j = 1; i < h; ++i ){ while( eu_dis2( X[ stk[ i ] ], Y[ stk[ i ] ], X[ stk[ j ] ], Y[ stk[ j ] ] ) <= eu_dis2( X[ stk[ i ] ], Y[ stk[ i ] ], X[ stk[ j + 1 ] ], Y[ stk[ j + 1 ] ] ) ) ++j, assert( j < stk.size() ); upmax( ans, 2.0 + eu_dis( X[ stk[ i ] ], Y[ stk[ i ] ], X[ stk[ j ] ], Y[ stk[ j ] ] ) ); } } cout << fixed << setprecision( 8 ) << ans << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }