結果

問題 No.1701 half price
ユーザー hiro71687khiro71687k
提出日時 2023-08-10 05:10:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 490 ms / 3,000 ms
コード長 924 bytes
コンパイル時間 4,392 ms
コンパイル使用メモリ 267,892 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 22:30:01
合計ジャッジ時間 6,958 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 48 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 48 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 490 ms
6,944 KB
testcase_07 AC 485 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,948 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 177 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 487 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=1000000007;
ll inf=10099999999999990;
int main(){
    ll n,w;
    cin  >> n >> w;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll>thr(20,1),two(20,1);
    for (ll i = 1; i < 20; i++)
    {
        thr[i]=thr[i-1]*3;
        two[i]=two[i-1]*2;
    }
    ll ans=0;
    map<ll,ll>memo;
    for (ll i = 0; i <thr[n] ; i++)
    {
        ll x=0;
        ll z=0;
        for (ll j = 0; j < n; j++)
        {
            ll y=i%thr[j+1];
            y/=thr[j];
            x+=(a[j]*y)/2;
            if (y>=1)
            {
                z+=two[j];
            }
        }
        if (x==w&&z>=1)
        {
            memo[z]++;
        }
    }for(auto v:memo){
        ans++;
    }
    cout << ans << endl;
}
0