結果

問題 No.2453 Seat Allocation
ユーザー otoshigootoshigo
提出日時 2023-09-01 22:15:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,668 bytes
コンパイル時間 898 ms
コンパイル使用メモリ 88,760 KB
実行使用メモリ 8,232 KB
最終ジャッジ日時 2023-09-07 15:35:34
合計ジャッジ時間 3,628 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 68 ms
7,840 KB
testcase_06 AC 43 ms
7,044 KB
testcase_07 AC 29 ms
4,624 KB
testcase_08 AC 8 ms
4,376 KB
testcase_09 AC 149 ms
7,772 KB
testcase_10 AC 100 ms
7,840 KB
testcase_11 AC 125 ms
7,852 KB
testcase_12 AC 41 ms
8,232 KB
testcase_13 AC 40 ms
6,920 KB
testcase_14 AC 43 ms
7,212 KB
testcase_15 AC 47 ms
7,808 KB
testcase_16 AC 42 ms
7,916 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 112 ms
7,144 KB
testcase_19 AC 147 ms
7,420 KB
testcase_20 AC 57 ms
5,232 KB
testcase_21 AC 55 ms
5,492 KB
testcase_22 AC 75 ms
7,256 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const double eps=1e-12;

bool compare(tuple<ll,ll,int>&t1,tuple<ll,ll,int>&t2){
    if(get<0>(t1)*get<1>(t2)>get<1>(t1)*get<0>(t2)){
        return true;
    }else if(get<0>(t1)*get<1>(t2)<get<1>(t1)*get<0>(t2)){
        return false;
    }else{
        if(get<2>(t1)<get<2>(t2))return true;
        else return false;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M;
    cin>>N>>M;
    vector<ll>A(N),B(M);
    for(int i=0;i<N;i++)cin>>A[i];
    for(int i=0;i<M;i++)cin>>B[i];
    double ok=0,ng=2e9;
    for(int i=0;i<100;i++){
        double mid=(ok+ng)/2;
        int cnt=0;
        for(int i=0;i<N;i++){
            for(int j=0;j<M;j++){
                if(A[i]>B[j]*mid+eps){
                    cnt++;
                }else{
                    break;
                }
                if(cnt>=M)break;
            }
            if(cnt>=M)break;
        }
        if(cnt>=M)ok=mid;
        else ng=mid;
    }
    vector<tuple<ll,ll,int>>vp;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            if(A[i]>B[j]*ok+eps){
                vp.push_back(make_tuple(A[i],B[j],i));
            }else{
                break;
            }
        }
    }
    sort(all(vp),compare);
    for(int i=0;i<M;i++){
        cout<<get<2>(vp[i])+1<<"\n";
    }
}
0