結果

問題 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,106 ms
コンパイル使用メモリ 100,376 KB
最終ジャッジ日時 2024-11-15 01:01:49
合計ジャッジ時間 1,497 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:94:19: error: aggregate 'std::array<int, 9> t' has incomplete type and cannot be defined
   94 |     array<int, 9> t;
      |                   ^
main.cpp:98:23: error: variable 'std::array<int, 9> x' has initializer but incomplete type
   98 |         array<int, 9> x = t, y{};
      |                       ^
main.cpp:98:30: error: variable 'std::array<int, 9> y' has initializer but incomplete type
   98 |         array<int, 9> x = t, y{};
      |                              ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_tree.h:69,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/map:60,
                 from main.cpp:3:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ext/aligned_buffer.h: In instantiation of 'struct __gnu_cxx::__aligned_membuf<std::array<int, 9> >':
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_tree.h:231:41:   required from 'struct std::_Rb_tree_node<std::array<int, 9> >'
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_tree.h:1937: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> >*]'
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_tree.h:986: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> >]'
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_set.h:167:7:   required from here

ソースコード

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