結果

問題 No.2453 Seat Allocation
ユーザー erbowlerbowl
提出日時 2023-09-01 21:50:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 275 ms / 2,000 ms
コード長 5,427 bytes
コンパイル時間 2,092 ms
コンパイル使用メモリ 209,824 KB
実行使用メモリ 6,828 KB
最終ジャッジ日時 2023-09-07 15:35:03
合計ジャッジ時間 6,488 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 234 ms
6,700 KB
testcase_06 AC 173 ms
4,380 KB
testcase_07 AC 39 ms
6,124 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 275 ms
6,764 KB
testcase_10 AC 265 ms
6,676 KB
testcase_11 AC 265 ms
6,828 KB
testcase_12 AC 167 ms
4,376 KB
testcase_13 AC 179 ms
4,376 KB
testcase_14 AC 174 ms
4,376 KB
testcase_15 AC 187 ms
4,376 KB
testcase_16 AC 166 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 195 ms
5,148 KB
testcase_19 AC 218 ms
6,352 KB
testcase_20 AC 89 ms
4,600 KB
testcase_21 AC 134 ms
4,376 KB
testcase_22 AC 192 ms
4,692 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef long long ll;
typedef long double ld;

#include <bits/stdc++.h>
using namespace std;
#define int long long

// modint
template<int MOD> struct Fp {
    // inner value
    long long val;
    
    // constructor
    constexpr Fp() noexcept : val(0) { }
    constexpr Fp(long long v) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr long long get() const noexcept { return val; }
    constexpr int get_mod() const noexcept { return MOD; }
    
    // arithmetic operators
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp &r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp &r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp &r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp &r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp &r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp &r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp &r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp &r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b, swap(a, b);
            u -= t * v, swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp pow(long long n) const noexcept {
        Fp res(1), mul(*this);
        while (n > 0) {
            if (n & 1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    constexpr Fp inv() const noexcept {
        Fp res(1), div(*this);
        return res / div;
    }

    // other operators
    constexpr bool operator == (const Fp &r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp &r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD> &x) noexcept {
        is >> x.val;
        x.val %= MOD;
        if (x.val < 0) x.val += MOD;
        return is;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD> &x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &r, long long n) noexcept {
        return r.pow(n);
    }
    friend constexpr Fp<MOD> modinv(const Fp<MOD> &r) noexcept {
        return r.inv();
    }
};


struct Eratos {
    vector<int> primes;
    vector<bool> isprime;
    vector<int> mebius;
    vector<int> min_factor;

    Eratos(int MAX) : primes(),
                      isprime(MAX+1, true),
                      mebius(MAX+1, 1),
                      min_factor(MAX+1, -1) {
        isprime[0] = isprime[1] = false;
        min_factor[0] = 0, min_factor[1] = 1;
        for (int i = 2; i <= MAX; ++i) {
            if (!isprime[i]) continue;
            primes.push_back(i);
            mebius[i] = -1;
            min_factor[i] = i;
            for (int j = i*2; j <= MAX; j += i) {
                isprime[j] = false;
                if ((j / i) % i == 0) mebius[j] = 0;
                else mebius[j] = -mebius[j];
                if (min_factor[j] == -1) min_factor[j] = i;
            }
        }
    }

    // prime factorization
    vector<pair<int,int>> prime_factors(int n) {
        vector<pair<int,int> > res;
        while (n != 1) {
            int prime = min_factor[n];
            int exp = 0;
            while (min_factor[n] == prime) {
                ++exp;
                n /= prime;
            }
            res.push_back(make_pair(prime, exp));
        }
        return res;
    }

    // enumerate divisors
    vector<int> divisors(int n) {
        vector<int> res({1});
        auto pf = prime_factors(n);
        for (auto p : pf) {
            int n = (int)res.size();
            for (int i = 0; i < n; ++i) {
                int v = 1;
                for (int j = 0; j < p.second; ++j) {
                    v *= p.first;
                    res.push_back(res[i] * v);
                }
            }
        }
        return res;
    }
};


signed main(){
    ll n,m;
    std::cin >> n>>m;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    vector<ll> b(m);
    for (int i = 0; i < m; i++) {
        std::cin >> b[i];
    }
    // 正当iのj番目の候補
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, function<bool(pair<ll,ll>,pair<ll,ll>)>>pq(
        [&](pair<ll,ll> l,pair<ll,ll> r){
            // std::cout << a[r.first]<<" "<<b[r.second]<<" "<<a[l.first]<<" "<<b[l.second] << std::endl;
            if(a[l.first]*b[r.second]!=a[r.first]*b[l.second]){
                return a[l.first]*b[r.second]<a[r.first]*b[l.second];
            }else{
                return l.first>r.first;
            }
        }
    );
    for (int i = 0; i < n; i++) {
        pq.push({i, 0});
    }
    for (int i = 0; i < m; i++) {
        auto [s,k] = pq.top();pq.pop();
        // std::cout << s<<" "<<k << std::endl;
        std::cout << s+1 << std::endl;
        if(k<m-1){
            pq.push({s,k+1});
        }
    }
};
0