結果

問題 No.2562 数字探しゲーム(緑以下コンver.)
ユーザー Keitaro NaruseKeitaro Naruse
提出日時 2023-12-02 16:56:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 13,480 KB
最終ジャッジ日時 2023-12-02 16:56:28
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,004 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 * @file 2562.cpp
 * @brief yukicoder No.2562 数字探しゲーム(緑以下コンver.)
 * @author Keitaro Naruse
 * @date 2023-12-02
 * @copyright MIT License
 * @details https://yukicoder.me/problems/no/2562
 * */

// # Solution

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

template < class T >
std::ostream& operator<<( std::ostream& os, const std::vector< T >& v ) {
    for( auto it = v.begin( ); it != v.end( ); it++ ) {
        os << *it << ( it == --v.end( ) ? "" : " " );
    }
    return os;
}

int main( ) {
    //  Read T = [ 1, 10^4 ]
    int T;
    std::cin >> T;

    //  Multiple queries
    for( int t = 0; t < T; t++ ) {
        //  Read M = [ 1, 10^9 ]
        long long M;
        std::cin >> M;
        //  Read di = [ 1, 9 ]
        std::vector< int > d( 10 );
        for( int i = 1; i <= 9; i++ ) {
            std::cin >> d.at( i );
        }

        //  Main::Preprocess
        std::string digits;
        for( int i = 1; i <= 9; i++ ) {
            for( char j = 0; j < d.at( i ); j++ ) {
                digits.push_back( '0' + i );
            }
        }
        long long answer = 0LL;
        do {
            long long val = std::stoll( digits );
            if( val % M == 0LL ) {
                answer = val;
                break;
            }
        } while( std::next_permutation( digits.begin( ), digits.end( ) ) );
        //  Main::Find a solution
        //  Main::Output a solution
        std::cout << answer << std::endl;
    }

    //  Finalize
    return 0;
}
0