結果

問題 No.1463 Hungry Kanten
ユーザー firiexpfiriexp
提出日時 2021-04-28 09:48:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,862 bytes
コンパイル時間 1,242 ms
コンパイル使用メモリ 99,112 KB
最終ジャッジ日時 2023-09-21 10:33:57
合計ジャッジ時間 1,741 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:94:19: エラー: aggregate ‘std::array<int, 9> t’ has incomplete type and cannot be defined
   94 |     array<int, 9> t;
      |                   ^
main.cpp:98:23: エラー: variable ‘std::array<int, 9> x’ has initializer but incomplete type
   98 |         array<int, 9> x = t, y{};
      |                       ^
main.cpp:98:30: エラー: variable ‘std::array<int, 9> y’ has initializer but incomplete type
   98 |         array<int, 9> x = t, y{};
      |                              ^
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/stl_tree.h:69,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/map:60,
         次から読み込み:  main.cpp:3:
/usr/local/gcc7/include/c++/12.2.0/ext/aligned_buffer.h: In instantiation of ‘struct __gnu_cxx::__aligned_membuf<std::array<int, 9> >’:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_tree.h:231:41:   required from ‘struct std::_Rb_tree_node<std::array<int, 9> >’
/usr/local/gcc7/include/c++/12.2.0/bits/stl_tree.h:1935:21:   required from ‘void std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_erase(_Link_type) [with _Key = std::array<int, 9>; _Val = std::array<int, 9>; _KeyOfValue = std::_Identity<std::array<int, 9> >; _Compare = std::less<std::array<int, 9> >; _Alloc = std::allocator<std::array<int, 9> >; _Link_type = std::_Rb_tree_node<std::array<int, 9> >*]’
/usr/local/gcc7/include/c++/12.2.0/bits/stl_tree.h:984:9:   required from ‘std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::~_Rb_tree() [with _Key = std::array<int, 9>; _Val = std::array<int, 9>; _KeyOfValue = std::_Identity<std::array<int, 9> >; _Compare = std::less<std::array<int, 9> >; _Alloc = std::allocator<std::array<int, 9> >]’
/usr/local/gcc7/include/c++/12.2.0/bits/stl_set.h:167:7:   required from here
/usr/local/gcc7/include/c++/12.2.0/ext/aligned_buffer.h:56:65: エラー: invalid application of ‘sizeof’ to 

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

#include <chrono>
class xor_shift {
    uint32_t x, y, z, w;
public:
    xor_shift() : x(static_cast<uint32_t>((chrono::system_clock::now().time_since_epoch().count())&((1LL << 32)-1))),
    y(1068246329), z(321908594), w(1234567890) {};

    uint32_t urand(){
        uint32_t t;
        t = x ^ (x << 11);
        x = y; y = z; z = w;
        w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
        return w;
    };

    int rand(int n){
        if(n < 0) return -rand(-n);
        uint32_t t = numeric_limits<uint32_t>::max()/(n+1)*(n+1);
        uint32_t e = urand();
        while(e >= t) e = urand();
        return static_cast<int>(e%(n+1));
    }

    int rand(int a, int b){
        if(a > b) swap(a, b);
        return a+rand(b-a);
    }
};

template< class T>
T pow_ (T x, uint64_t n, uint64_t M){
    T u = 1;
    if(n > 0){
        u = pow_(x, n/2, M);
        if (n % 2 == 0) u = (u*u) % M;
        else u = (((u * u)% M) * x) % M;
    }
    return u;
};

bool suspect(__uint128_t a, uint64_t s, uint64_t d, uint64_t n){
    __uint128_t x = pow_(a, d, n);
    if (x == 1) return true;
    for (int r = 0; r < s; ++r) {
        if(x == n-1) return true;
        x = x * x % n;
    }
    return false;
}

template<class T>
bool miller_rabin(T m){
    uint64_t n = m;
    if (n <= 1 || (n > 2 && n % 2 == 0)) return false;
    uint64_t d = n - 1, s = 0;
    while (!(d&1)) {++s; d >>= 1;}
    vector<uint64_t> v = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
    if(n <= 4759123141LL) v = {2, 7, 61};
    for (auto &&p : v) {
        if(p >= n) break;
        if(!suspect(p, s, d, n)) return false;
    }
    return true;
}
constexpr int ms[] = {1761671,1212889,1058203,1548103,1523551,1176391,1787453,1901021,1176533};
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    xor_shift rd;
    ll st = 1e15;
    auto m = rd.rand(st, st*5);
    while(!miller_rabin(m)) m = rd.rand(st, st*5);
    set<array<int, 9>> s;
    array<int, 9> t;
    fill(t.begin(),t.end(), 1);
    for (int i = 0; i < (1 << n); ++i) {
        if(__builtin_popcount(i) < k) continue;
        array<int, 9> x = t, y{};
        for (int j = 0; j < n; ++j) {
            if(i & (1 << j)){
                for (int l = 0; l < 9; ++l) {
                    (x[l] *= v[j]) %= ms[l];
                    y[l] += v[j];
                }
            }
        }
        s.emplace(x);
        s.emplace(y);
    }
    cout << s.size() << "\n";

    return 0;
}
0