結果

問題 No.1463 Hungry Kanten
ユーザー LayCurseLayCurse
提出日時 2021-04-02 23:07:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,449 bytes
コンパイル時間 3,072 ms
コンパイル使用メモリ 212,708 KB
実行使用メモリ 15,788 KB
最終ジャッジ日時 2023-08-25 15:05:04
合計ジャッジ時間 3,707 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,496 KB
testcase_01 AC 2 ms
5,524 KB
testcase_02 AC 5 ms
5,684 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,596 KB
testcase_05 AC 64 ms
15,788 KB
testcase_06 AC 2 ms
5,588 KB
testcase_07 AC 2 ms
5,380 KB
testcase_08 AC 2 ms
5,364 KB
testcase_09 AC 2 ms
5,372 KB
testcase_10 AC 2 ms
5,352 KB
testcase_11 AC 3 ms
5,372 KB
testcase_12 AC 2 ms
5,616 KB
testcase_13 AC 3 ms
5,352 KB
testcase_14 AC 3 ms
5,452 KB
testcase_15 AC 2 ms
5,384 KB
testcase_16 AC 4 ms
5,672 KB
testcase_17 AC 10 ms
6,392 KB
testcase_18 AC 4 ms
5,648 KB
testcase_19 AC 34 ms
9,460 KB
testcase_20 AC 40 ms
11,492 KB
testcase_21 AC 2 ms
5,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(__int128_t &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline int BIT_popcount_L(const int x){
  return __builtin_popcount(x);
}
inline int BIT_popcount_L(const long long x){
  return __builtin_popcountll(x);
}
template<class T> void Unique_L(int &N, T A[], int sorted=0){
  int i;
  int k;
  if(!sorted){
    sort(A, A+N);
  }
  k = 0;
  for(i=(0);i<(N);i++){
    if(k==0 || A[k-1]!=A[i]){
      A[k++] = A[i];
    }
  }
  N = k;
}
int N;
int K;
__int128_t A[18];
int sz;
__int128_t arr[1000000];
int main(){
  int mask;
  rd(N);
  rd(K);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(mask=(0);mask<(1<<N);mask++){
    if(BIT_popcount_L(mask)>= K){
      int i;
      __int128_t x = 0;
      __int128_t y = 1;
      for(i=(0);i<(N);i++){
        if(((mask) &(1<<(i)))){
          x += A[i];
          y *= A[i];
        }
      }
      arr[sz++] = x;
      arr[sz++] = y;
    }
  }
  Unique_L(sz, arr);
  wt_L(sz);
  wt_L('\n');
  return 0;
}
// cLay version 20210328-1 [beta]

// --- original code ---
// int N, K; __int128_t A[18];
// int sz; __int128_t arr[1d6];
// {
//   rd(N,K,A(N));
//   rep(mask,1<<N) if(BIT_popcount(mask) >= K){
//     __int128_t x = 0, y = 1;
//     rep(i,N) if(BIT_ith(mask,i)){
//       x += A[i];
//       y *= A[i];
//     }
//     arr[sz++] = x;
//     arr[sz++] = y;
//   }
//   Unique(sz, arr);
//   wt(sz);
// }
0