結果

問題 No.2203 POWER!!!!!
ユーザー 👑 p-adicp-adic
提出日時 2023-01-29 22:31:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,424 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 81,320 KB
実行使用メモリ 9,560 KB
最終ジャッジ日時 2024-07-02 18:43:55
合計ジャッジ時間 10,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 39 ms
5,376 KB
testcase_09 AC 284 ms
5,376 KB
testcase_10 AC 809 ms
5,376 KB
testcase_11 AC 1,779 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ( "O3" )
#pragma GCC optimize( "unroll-loops" )
#pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" )
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdint.h>
#include <cassert>
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 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 GETLINE_SEPARATE( A , SEPARATOR ) string A; getline( cin , A , SEPARATOR )
#define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ )
#define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT , 0 , HOW_MANY_TIMES )
#define QUIT return 0
#define COUT( ANSWER ) cout << ( ANSWER ) << "\n";
#define RETURN( ANSWER ) COUT( ANSWER ); 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 ) TYPE_OF( BOUND ) 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 ); } 

CEXPR( ll , lim_A , 9 );

class Power
{
public:
  ll m_val[lim_A][lim_A];
  inline constexpr Power() : m_val() { FOR( i , 1 , lim_A ){ ll ( &m_val_i )[lim_A] = m_val[i]; ll power = 1; FOR( j , 1 , lim_A ){ m_val_i[j] = power *= i; } } }
};

int main()
{
  UNTIE;
  CEXPR( int , bound_N , 200000 );
  GETLINE( N_str );
  COUNT_VARIABLE( N_str , 1 );
  STOI( N_str , N , bound_N );
  assert( 1 <= N );
  CEXPR( ll , bound_A , lim_A - 1 );
  int count[lim_A] = {};
  GETLINE( A_str );
  COUNT_VARIABLE( A_str , N );
  REPEAT( N ){
    STOI( A_str , Ai , bound_A );
    assert( 1 <= Ai );
    count[Ai]++;
  }
  CHECK_REDUNDANT_INPUT;
  constexpr Power power{};
  ll answer = 0;
  FOR( i , 0 , lim_A ){
    const ll ( &m_val_i )[lim_A] = power.m_val[i];
    int& count_i = count[i];
    FOR( j , 0 , lim_A ){
      answer += ( m_val_i[j] * count_i ) * count[j];
    }
  }
  RETURN( answer );
}
0