結果
問題 | No.2067 ±2^k operations |
ユーザー | 👑 p-adic |
提出日時 | 2022-09-18 16:23:26 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 900 ms / 2,000 ms |
コード長 | 2,861 bytes |
コンパイル時間 | 2,436 ms |
コンパイル使用メモリ | 215,568 KB |
実行使用メモリ | 114,048 KB |
最終ジャッジ日時 | 2024-06-01 15:33:59 |
合計ジャッジ時間 | 13,041 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 79 ms
15,616 KB |
testcase_02 | AC | 75 ms
15,488 KB |
testcase_03 | AC | 77 ms
15,744 KB |
testcase_04 | AC | 76 ms
15,616 KB |
testcase_05 | AC | 77 ms
15,616 KB |
testcase_06 | AC | 8 ms
6,940 KB |
testcase_07 | AC | 900 ms
114,048 KB |
testcase_08 | AC | 888 ms
113,920 KB |
testcase_09 | AC | 890 ms
113,664 KB |
testcase_10 | AC | 892 ms
113,792 KB |
testcase_11 | AC | 890 ms
113,920 KB |
testcase_12 | AC | 893 ms
113,664 KB |
testcase_13 | AC | 889 ms
113,792 KB |
testcase_14 | AC | 896 ms
113,792 KB |
testcase_15 | AC | 894 ms
113,792 KB |
testcase_16 | AC | 886 ms
113,792 KB |
testcase_17 | AC | 12 ms
6,940 KB |
testcase_18 | AC | 5 ms
6,944 KB |
testcase_19 | AC | 4 ms
6,944 KB |
testcase_20 | AC | 4 ms
6,944 KB |
testcase_21 | AC | 5 ms
6,944 KB |
testcase_22 | AC | 5 ms
6,944 KB |
testcase_23 | AC | 5 ms
6,940 KB |
ソースコード
// #define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; #define CIN( LL , A ) LL A; cin >> A #define GETLINE( A ) string A; getline( cin , A ) #define GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR ) #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( ll VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define FOR_ITR( ARRAY , ITR , END ) for( auto ITR = ARRAY .begin() , END = ARRAY .end() ; ITR != END ; ITR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define RETURN( ANSWER ) cout << ( ANSWER ) << "\n"; QUIT #define DOUBLE( PRECISION , ANSWER ) cout << fixed << setprecision( PRECISION ) << ( ANSWER ) << "\n"; QUIT #define MIN( A , B ) A < B ? A : B; #define MAX( A , B ) A < B ? B : A; template <typename T> inline T Absolute( const T& a ){ return a > 0 ? a : - a; } class seq { public: ll m_n; ll m_i; inline seq() : m_n() , m_i() {} inline seq( const ll& n , const ll& i ) : m_n( n ) , m_i( i ) {} }; class ord { public: inline bool operator()( const seq& N0 , const seq& N1 ) { return N0.m_n < N1.m_n; } }; inline const ll& f( const ll& n ) { static map<ll,ll> answer{}; return answer.count( n ) == 1 ? answer[n] : answer[n] = ( n == 0 ? 0 : n % 2 == 0 ? f( n / 2 ) : f( ( n + 1 ) / 4 ) + 1 ); } // ( ( max - 1 ) / 4 - ( start + 2 ) / 4 + 1 ) + ( max + 1 ) / 4 - ( start / 4 + 1 + 1 ) // = ( ( max - 1 ) / 4 + ( max + 1 ) / 4 ) - ( ( start + 2 ) / 4 + start / 4 ) + 1 // = ( max + 1 ) / 2 - start / 2 inline const ll& sum_f( const ll& start , const ll& max ) { static map<ll,map<ll,ll> > answer{}; static const ll zero{ 0 }; if( start > max ){ return zero; } else if( start == max ){ return f( start ); } map<ll,ll>& answer_start = answer[start]; return answer_start.count( max ) ? answer_start[max] : answer_start[max] = sum_f( ( start + 1 ) / 2 , max / 2 ) + sum_f( ( start + 2 ) / 4 , start / 4 ) + sum_f( start / 4 + 1 , ( max - 1 ) / 4 ) * 2 + sum_f( ( max + 3 ) / 4 , ( max + 1 ) / 4 ) + ( max + 1 ) / 2 - start / 2; } int main() { UNTIE; CIN( ll , T ); seq N[10000]; FOR( i , 0 , T ){ seq& Ni = N[i]; cin >> Ni.m_n; Ni.m_i = i; } sort( N , N + T , ord() ); ll answer[10000]; ll* p_N_prev; ll* p_answer_prev; { seq& Ni = N[0]; ll& answer_new = answer[ Ni.m_i ]; answer_new = sum_f( 1 , Ni.m_n ); p_N_prev = &( Ni.m_n ); p_answer_prev = &( answer_new ); } FOR( i , 1 , T ){ seq& Ni = N[i]; ll& answer_new = answer[ Ni.m_i ]; answer_new = *p_answer_prev + sum_f( *p_N_prev + 1 , Ni.m_n ); p_N_prev = &( Ni.m_n ); p_answer_prev = &( answer_new ); } FOR( i , 0 , T ){ cout << answer[i] << "\n"; } return 0; }