結果
問題 | No.96 圏外です。 |
ユーザー | 0w1 |
提出日時 | 2016-12-05 12:42:14 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,700 bytes |
コンパイル時間 | 1,917 ms |
コンパイル使用メモリ | 184,888 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-05-05 20:19:26 |
合計ジャッジ時間 | 22,640 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | TLE | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
ソースコード
#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( i ); } int h = stk.size(); for( int i = ( 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( 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; 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; }