結果

問題 No.2453 Seat Allocation
ユーザー milanis48663220milanis48663220
提出日時 2023-09-01 22:28:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 3,524 bytes
コンパイル時間 1,164 ms
コンパイル使用メモリ 124,860 KB
実行使用メモリ 7,648 KB
最終ジャッジ日時 2023-09-07 15:36:19
合計ジャッジ時間 5,107 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 178 ms
7,612 KB
testcase_06 AC 154 ms
4,376 KB
testcase_07 AC 30 ms
7,068 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 206 ms
7,648 KB
testcase_10 AC 209 ms
7,324 KB
testcase_11 AC 207 ms
7,380 KB
testcase_12 AC 141 ms
4,380 KB
testcase_13 AC 147 ms
4,376 KB
testcase_14 AC 147 ms
4,376 KB
testcase_15 AC 157 ms
4,376 KB
testcase_16 AC 150 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 159 ms
5,440 KB
testcase_19 AC 172 ms
7,408 KB
testcase_20 AC 71 ms
5,236 KB
testcase_21 AC 114 ms
4,380 KB
testcase_22 AC 165 ms
4,580 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

template <typename T>
class frac{
    public:
    T n, d;
    frac(T _n, T _d){
        T g = gcd(_n, _d);
        n = _n/g;
        d = _d/g;
        if(d < 0) {
            d *= -1;
            n *= -1;
        }
    }
    frac operator+(frac f){
        return frac(n*f.d+d*f.n, f.d*d);
    }
    frac operator-(frac f){
        return frac(n*f.d-d*f.n, f.d*d);
    }
    frac operator*(frac f){
        return frac(f.n*n, f.d*d);
    }
    frac inv(){
        return frac(d, n);
    }
    bool operator<(frac f){
        if(d*f.d < 0) return n*f.d-d*f.n > 0;
        else return n*f.d-d*f.n < 0;
    }
    bool operator>(frac f){
        if(d*f.d < 0) return n*f.d-d*f.n < 0;
        else return n*f.d-d*f.n > 0;
    }
    bool operator==(frac f){
        return n*f.d-d*f.n == 0;
    }
    void operator+=(frac f){
        n = n*f.d+d*f.n, d = f.d*d;
        reduction();
    }
    void operator-=(frac f){
        n = n*f.d-d*f.n, d = f.d*d;
        reduction();
    }
    void reduction(){
        T g = gcd(n, d);
        n /= g, d /= g;
    }
};

template <typename T>
bool operator<(const frac<T> f1, const frac<T> f2){
    if(f1.d*f2.d < 0) return f1.n*f2.d-f1.d*f2.n > 0;
    else return f1.n*f2.d-f1.d*f2.n < 0;
}

template <typename T>
bool operator>(const frac<T> f1, const frac<T> f2){
    if(f1.d*f2.d < 0) return f1.n*f2.d-f1.d*f2.n > 0;
    else return f1.n*f2.d-f1.d*f2.n > 0;
}

template <typename T>
bool operator==(const frac<T> f1, const frac<T> f2){
    return f1.n*f2.d-f1.d*f2.n == 0;
}

template <typename T>
ostream& operator<<(ostream& os, const frac<T>& f){
    os << f.n << '/' << f.d;
    return os;
}

using F = frac<ll>;
using P = pair<F, int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int> b(m);
    for(int i = 0; i < m; i++) cin >> b[i];
    vector<int> cur(n, 0);
    priority_queue<P> que;
    for(int i = 0; i < n; i++){
        que.push({F(a[i], b[0]), -i});
    }
    for(int it = 0; it < m; it++){
        auto [_, ii] = que.top(); que.pop();
        int i = -ii;
        cout << i+1 << endl;
        {
            cur[i]++;
            if(cur[i] < m){
                que.push({F(a[i], b[cur[i]]), -i});
            }
        }
    }
}
0