結果
問題 | No.2453 Seat Allocation |
ユーザー | rniya |
提出日時 | 2023-09-01 21:52:10 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 6,246 bytes |
コンパイル時間 | 2,272 ms |
コンパイル使用メモリ | 208,772 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-06-25 09:24:37 |
合計ジャッジ時間 | 4,167 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 50 ms
7,680 KB |
testcase_06 | AC | 23 ms
5,376 KB |
testcase_07 | AC | 16 ms
7,200 KB |
testcase_08 | AC | 6 ms
5,376 KB |
testcase_09 | AC | 64 ms
7,548 KB |
testcase_10 | AC | 63 ms
7,488 KB |
testcase_11 | AC | 64 ms
7,552 KB |
testcase_12 | AC | 23 ms
5,376 KB |
testcase_13 | AC | 26 ms
5,376 KB |
testcase_14 | AC | 22 ms
5,376 KB |
testcase_15 | AC | 33 ms
5,376 KB |
testcase_16 | AC | 25 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 42 ms
5,636 KB |
testcase_19 | AC | 52 ms
7,304 KB |
testcase_20 | AC | 22 ms
5,376 KB |
testcase_21 | AC | 27 ms
5,376 KB |
testcase_22 | AC | 39 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> #ifdef LOCAL #include <debug.hpp> #else #define debug(...) void(0) #endif template <typename T, bool Reduce = false> class Rational { T num, den; static T my_gcd(T x_, T y_) { unsigned long long x = x_ < 0 ? -x_ : x_, y = y_ < 0 ? -y_ : y_; if (!x or !y) return x + y; int n = __builtin_ctzll(x), m = __builtin_ctzll(y); x >>= n, y >>= m; while (x != y) { if (x > y) x = (x - y) >> __builtin_ctzll(x - y); else y = (y - x) >> __builtin_ctzll(y - x); } return x << (n > m ? m : n); } void normalize() { if (den < 0) num = -num, den = -den; if (den == 0) num = (num > 0 ? 1 : num < 0 ? -1 : 0); if constexpr (Reduce) { T g = my_gcd(num, den); if (g > 0) num /= g, den /= g; } } public: Rational() {} Rational(T num) : num(num), den(T(1)) {} Rational(T num, T den) : num(num), den(den) { normalize(); } Rational operator+(const Rational& r) const { return Rational(num * r.den + den * r.num, den * r.den); } Rational operator-(const Rational& r) const { return Rational(num * r.den - den * r.num, den * r.den); } Rational operator*(const Rational& r) const { return Rational(num * r.num, den * r.den); } Rational operator/(const Rational& r) const { return Rational(num * r.den, den * r.num); } Rational& operator+=(const Rational& r) { return *this = *this + r; } Rational& operator-=(const Rational& r) { return *this = *this - r; } Rational& operator*=(const Rational& r) { return *this = *this * r; } Rational& operator/=(const Rational& r) { return *this = *this / r; } Rational operator+(const T& val) const { return *this + Rational(val); } Rational operator-(const T& val) const { return *this - Rational(val); } Rational operator*(const T& val) const { return *this * Rational(val); } Rational operator/(const T& val) const { return *this / Rational(val); } Rational& operator+=(const T& val) { return *this = *this + val; } Rational& operator-=(const T& val) { return *this = *this - val; } Rational& operator*=(const T& val) { return *this = *this * val; } Rational& operator/=(const T& val) { return *this = *this / val; } friend Rational operator+(const T& val, const Rational& r) { return r + val; } friend Rational operator-(const T& val, const Rational& r) { return r - val; } friend Rational operator*(const T& val, const Rational& r) { return r * val; } friend Rational operator/(const T& val, const Rational& r) { return r / val; } Rational operator-() const { return Rational(-num, den); } Rational abs() const { return Rational(num < 0 ? -num : num, den); } bool operator==(const Rational& r) const { if (den == 0 and r.den == 0) return num == r.num; if (den == 0 or r.den == 0) return false; return num * r.den == den * r.num; } bool operator!=(const Rational& r) const { return !(*this == r); } bool operator<(const Rational& r) const { if (den == 0 and r.den == 0) return num < r.num; if (den == 0) return num < 0; if (r.den == 0) return r.num > 0; return num * r.den < den * r.num; } bool operator<=(const Rational& r) const { return (*this == r) or (*this < r); } bool operator>(const Rational& r) const { return r < *this; } bool operator>=(const Rational& r) const { return (*this == r) or (*this > r); } bool operator==(const T& val) const { return *this == Rational(val); } bool operator!=(const T& val) const { return *this != Rational(val); } bool operator<(const T& val) const { return *this < Rational(val); } bool operator<=(const T& val) const { return *this <= Rational(val); } bool operator>(const T& val) const { return *this > Rational(val); } bool operator>=(const T& val) const { return *this >= Rational(val); } friend bool operator==(const T& val, const Rational& r) { return r == val; } friend bool operator!=(const T& val, const Rational& r) { return r != val; } friend bool operator<(const T& val, const Rational& r) { return r > val; } friend bool operator<=(const T& val, const Rational& r) { return r >= val; } friend bool operator>(const T& val, const Rational& r) { return r < val; } friend bool operator>=(const T& val, const Rational& r) { return r <= val; } explicit operator double() const { return (double)num / (double)den; } explicit operator long double() const { return (long double)num / (long double)den; } friend std::ostream& operator<<(std::ostream& os, const Rational& r) { return os << r.num << '/' << r.den; } }; using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); } template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); } template <class T> void mkuni(vector<T>& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } using R = Rational<ll>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<int> A(N), B(M); cin >> A >> B; priority_queue<pair<R, int>> pq; vector<int> cur(N, 0); for (int i = 0; i < N; i++) pq.emplace(R(A[i], B[cur[i]++]), -i); for (int i = 0; i < M; i++) { auto [val, idx] = pq.top(); pq.pop(); idx *= -1; cout << idx + 1 << '\n'; if (cur[idx] < M) pq.emplace(R(A[idx], B[cur[idx]++]), -idx); } return 0; }