結果
問題 | No.2177 Recurring ab |
ユーザー | 👑 p-adic |
提出日時 | 2022-11-16 23:46:48 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,347 bytes |
コンパイル時間 | 2,101 ms |
コンパイル使用メモリ | 204,340 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-17 18:15:00 |
合計ジャッジ時間 | 2,875 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,944 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,940 KB |
ソースコード
// 入力フォーマットチェックその2 #include<bits/stdc++.h> using namespace std; using ll = long long; #define TYPE_OF( VAR ) remove_const<remove_reference<decltype( VAR )>::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( MIN <= A && A <= MAX ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define GETLINE( A ) string A; getline( cin , A ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT // #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; cin >> VARIABLE_FOR_CHECK_REDUNDANT_INPUT; assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); #define CHECK_REDUNDANT_INPUT string VARIABLE_FOR_CHECK_REDUNDANT_INPUT = ""; getline( cin , VARIABLE_FOR_CHECK_REDUNDANT_INPUT ); assert( VARIABLE_FOR_CHECK_REDUNDANT_INPUT == "" ); assert( ! cin ); // |N| < BOUNDを満たすNをSから構築 #define STOI( S , N , BOUND ) ll N = 0; { bool VARIABLE_FOR_POSITIVITY_FOR_STOI = true; assert( S != "" ); if( S.substr( 0 , 1 ) == "-" ){ VARIABLE_FOR_POSITIVITY_FOR_STOI = false; S = S.substr( 1 ); assert( S != "" ); } assert( S.substr( 0 , 1 ) != " " ); while( S == "" ? false : S.substr( 0 , 1 ) != " " ){ assert( N < BOUND / 10 ? true : N == BOUND / 10 && stoi( S.substr( 0 , 1 ) ) < BOUND % 10 ); N = N * 10 + stoi( S.substr( 0 , 1 ) ); S = S.substr( 1 ); } if( ! VARIABLE_FOR_POSITIVITY_FOR_STOI ){ N *= -1; } if( S != "" ){ S = S.substr( 1 ); } } // 1行で入力される変数の個数が適切か確認(半角空白の個数+1を調べる) #define COUNT_VARIABLE( S , VARIABLE_NUMBER ) { int size = S.size(); int count = 0; for( int i = 0 ; i < size ; i++ ){ if( S.substr( i , 1 ) == " " ){ count++; } } assert( count + 1 == VARIABLE_NUMBER ); } int main() { CEXPR( ll , bound_N , 100000000 ); GETLINE( N_str ); COUNT_VARIABLE( N_str , 1 ); STOI( N_str , N , bound_N + 1 ); CHECK_REDUNDANT_INPUT; // (pa+b)/(p^2-1) > 1/N // <=> N(pa+b) > p^2-1 // <=> p^2 - Nap - (Nb+1) < 0 // <=> Na/2 - (sqrt((Na)^2+4(Nb+1)))/2 < p < Na/2 + (sqrt((Na)^2+4(Nb+1)))/2 ll answer = 0; ll Na = -N; CEXPR( ll , bound_ab , 10 ); CEXPR( ll , bound_p , 1000000000 ); FOR( a , 0 , bound_ab ){ Na += N; ll Na2 = Na * Na; double Na_half = Na / 2.0; ll Nb_plus = -N + 1; FOR( b , 0 , bound_ab ){ Nb_plus += N; if( a != b ){ double r = sqrt( Na2 + 4 * Nb_plus ) / 2.0; ll low = Na_half - r; if( low * low - Na * low - Nb_plus >= 0 ){ low++; } low = max( max( max( a , b ) + 1 , (ll)2 ) , low ); ll upp = Na_half + r; if( upp * upp - Na * upp - Nb_plus >= 0 ){ upp--; } upp = min( bound_p , upp ); if( low <= upp ){ answer += upp - low + 1; // デバッグ用 // for( ll p = low ; p <= upp ; p++ ){ // cout << "(p,a,b) = (" << p << "," << a << "," << b << ")" << endl; // assert( ( p * a + b ) * N > p * p - 1 ); // assert( 2 <= p && a <= p - 1 && b <= p - 1 && p <= bound_p ); // } } } } } RETURN( answer ); }