結果

問題 No.1463 Hungry Kanten
ユーザー abc3
提出日時 2021-04-02 23:23:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,758 bytes
コンパイル時間 2,251 ms
コンパイル使用メモリ 202,140 KB
最終ジャッジ日時 2025-01-20 10:05:17
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

    #include <bits/stdc++.h>
    using namespace std;
    #include <math.h>
    #include <iomanip>
    #include <cstdint>
    #include <string>
    #include <sstream>
    #include <iostream>
    template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
    template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
    #define rep(i,n) for (int i = 0; i < (n); ++i)
    typedef long long ll;
    using P=pair<int,int>;
    const int INF=1001001001;
    const int mod=1e9+7;
    std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}

__int128 parse(string &s) {
  __int128 ret = 0;
  for (int i = 0; i < s.length(); i++)
    if ('0' <= s[i] && s[i] <= '9')
      ret = 10 * ret + s[i] - '0';
  return ret;
}

    int main(){
      int n,k;
      cin>>n>>k;
      vector<ll>a(n);
      rep(i,n){cin>>a[i];}
      set<__int128>st;
      rep(mask,1<<n){
        if(__builtin_popcount(mask)<k){continue;}
        string s="0",s2="1";
        __int128 l=parse(s),r=parse(s2);
        rep(i,n){
          if((mask>>i)&1){
            string t=to_string(a[i]);
            l+=parse(t);
            r*=parse(t);
          }
        }
        st.insert(l);
        st.insert(r);
      }
      cout<<st.size()<<endl;
      return 0;
    }
0