結果

問題 No.2453 Seat Allocation
ユーザー 憩いの場憩いの場
提出日時 2023-09-01 23:37:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,268 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 76,880 KB
実行使用メモリ 7,616 KB
最終ジャッジ日時 2023-09-07 15:38:01
合計ジャッジ時間 5,298 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 236 ms
7,404 KB
testcase_06 AC 170 ms
4,384 KB
testcase_07 AC 37 ms
6,992 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 262 ms
7,616 KB
testcase_10 AC 264 ms
7,280 KB
testcase_11 AC 261 ms
7,240 KB
testcase_12 AC 170 ms
4,376 KB
testcase_13 AC 175 ms
4,380 KB
testcase_14 AC 170 ms
4,380 KB
testcase_15 AC 179 ms
4,376 KB
testcase_16 AC 165 ms
4,384 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 193 ms
5,524 KB
testcase_19 AC 221 ms
7,112 KB
testcase_20 AC 84 ms
5,136 KB
testcase_21 AC 128 ms
4,384 KB
testcase_22 AC 189 ms
4,480 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<queue>

using namespace std;

class Flaction
{
public:
    long long a, b;
    int id;
public:
    Flaction( void ) = default;
    Flaction( long long a, long long b, int id ) : a( a ), b( b ), id( id ) {};

    int getID( void ) { return this->id; }

    bool operator < ( const Flaction &flac ) const
    {
        if( this->a * flac.b == flac.a * this->b ) return this->id > flac.id;
        else return this->a * flac.b < flac.a * this->b;
    }
};

int main( void )
{
    int N, M;
    cin >> N >> M;
    vector<int> A( N ), B( M );
    for( int i = 0; i < N; i++ )
    {
        cin >> A[i];
    }
    for( int i = 0; i < M; i++ )
    {
        cin >> B[i];
    }
    
    priority_queue<Flaction> q;
    vector<int> counter( N, 0 );
    for( int i = 0; i < N; i++ )
    {
        q.push( Flaction( A[i], B[0], i ) );
    }
    
    Flaction max_people;
    for( int k = 0; k < M; k++ )
    {
        max_people = q.top(), q.pop();
        counter[max_people.getID()]++;
        if( counter[max_people.getID()] != M )
        {
            q.push( Flaction( A[max_people.getID()], B[counter[max_people.getID()]], max_people.getID() ) );
        }
        cout << max_people.getID() + 1 << endl;
    }

    return 0;
}
0