結果

問題 No.1231 Make a Multiple of Ten
ユーザー zuminzumin
提出日時 2021-02-25 22:57:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 71,220 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 02:16:06
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,948 KB
testcase_02 AC 1 ms
6,948 KB
testcase_03 AC 1 ms
6,948 KB
testcase_04 AC 40 ms
6,944 KB
testcase_05 AC 35 ms
6,948 KB
testcase_06 AC 15 ms
6,944 KB
testcase_07 AC 41 ms
6,944 KB
testcase_08 AC 13 ms
6,948 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 37 ms
6,944 KB
testcase_11 AC 44 ms
6,944 KB
testcase_12 AC 80 ms
6,944 KB
testcase_13 AC 84 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 84 ms
6,948 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:30:11: warning: 'md' may be used uninitialized [-Wmaybe-uninitialized]
   30 |         md+=ai;
      |         ~~^~~~
main.cpp:23:9: note: 'md' was declared here
   23 |     int md;
      |         ^~

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

bool rec(vector<int> cnt,int prev,int res,int md){
    if(res==0){
        return md==0;
    }
    bool ans=false;
    for(int i=prev-1;i>=1;i--){
        for(int j=1;j<=min(cnt[i],res);j++){
            cnt[i]-=j;
            ans|=rec(cnt,i,res-j,(md-i*j+10*j)%10);
            cnt[i]+=j;
        }
    }
    return ans;
}

int main(){
    int n;
    int md;
    vector<int> cnt(10,0);
    cin>>n;
    for(int i=0;i<n;i++){
        int ai;
        cin>>ai;
        cnt[ai%10]++;
        md+=ai;
        md%=10;
    }
    for(int i=0;i<=min(10,n);i++){
        if(rec(cnt,10,i,md)){
            cout<<n-i<<endl;
            return 0;
        }
    }

    return 0;
}
0