結果

問題 No.1460 Max of Min
ユーザー suzuken_wsuzuken_w
提出日時 2021-04-02 17:37:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,207 bytes
コンパイル時間 2,840 ms
コンパイル使用メモリ 223,056 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 01:55:29
合計ジャッジ時間 8,327 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 68 ms
4,380 KB
testcase_04 AC 69 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 7 ms
4,376 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 29 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 8 ms
4,384 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 7 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 7 ms
4,384 KB
testcase_30 AC 9 ms
4,380 KB
testcase_31 AC 6 ms
4,380 KB
testcase_32 AC 9 ms
4,384 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 4 ms
4,376 KB
testcase_35 AC 3 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 8 ms
4,376 KB
testcase_38 AC 7 ms
4,376 KB
testcase_39 AC 5 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 3 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 8 ms
4,380 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 5 ms
4,380 KB
testcase_47 AC 4 ms
4,376 KB
testcase_48 AC 12 ms
4,376 KB
testcase_49 AC 7 ms
4,376 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 8 ms
4,376 KB
testcase_52 AC 3 ms
4,380 KB
testcase_53 AC 6 ms
4,380 KB
testcase_54 AC 7 ms
4,376 KB
testcase_55 AC 9 ms
4,380 KB
testcase_56 AC 13 ms
4,380 KB
testcase_57 AC 9 ms
4,376 KB
testcase_58 AC 9 ms
4,376 KB
testcase_59 AC 10 ms
4,376 KB
testcase_60 AC 13 ms
4,380 KB
testcase_61 AC 13 ms
4,380 KB
testcase_62 AC 13 ms
4,376 KB
testcase_63 AC 2 ms
4,384 KB
testcase_64 AC 2 ms
4,380 KB
testcase_65 AC 8 ms
4,380 KB
testcase_66 AC 11 ms
4,384 KB
testcase_67 AC 4 ms
4,380 KB
testcase_68 AC 10 ms
4,384 KB
testcase_69 AC 6 ms
4,376 KB
testcase_70 AC 12 ms
4,376 KB
testcase_71 AC 7 ms
4,380 KB
testcase_72 AC 7 ms
4,376 KB
testcase_73 AC 7 ms
4,376 KB
testcase_74 AC 13 ms
4,380 KB
testcase_75 AC 13 ms
4,380 KB
testcase_76 AC 12 ms
4,380 KB
testcase_77 AC 14 ms
4,384 KB
testcase_78 AC 6 ms
4,380 KB
testcase_79 AC 16 ms
4,380 KB
testcase_80 AC 10 ms
4,380 KB
testcase_81 AC 5 ms
4,380 KB
testcase_82 AC 11 ms
4,376 KB
testcase_83 AC 8 ms
4,380 KB
testcase_84 AC 63 ms
4,376 KB
testcase_85 AC 38 ms
4,380 KB
testcase_86 AC 76 ms
4,384 KB
testcase_87 AC 74 ms
4,380 KB
testcase_88 AC 56 ms
4,380 KB
testcase_89 AC 47 ms
4,380 KB
testcase_90 AC 35 ms
4,376 KB
testcase_91 AC 64 ms
4,380 KB
testcase_92 AC 70 ms
4,380 KB
testcase_93 AC 29 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
V<ll> a,b;
ll n,k;
bool ok(ll m){
      V<ll> cb;
      for(int i=0;i<k;i++)if(b[k-i-1]>=m)cb.emplace_back(i+1);
      if(cb.size()==0)return false;
      int  siz=cb.back();
      V<ll> dp(siz,2*inf);
      for(ll i=0;i<k;i++){
           if(a[i]>=m){
                for(int c:cb)if(i+c>=k)chmin(dp[(i+c)%siz],i+c);
           }
      }
      priority_queue<P,V<P>,greater<P>> pq;
      for(int i=0;i<siz;i++){
            pq.emplace(dp[i],i);
      }
      while(pq.size()){
             auto [v,cur]=pq.top();
             pq.pop();
             if(dp[cur]!=v)continue;
             if(v>n)return false;
             if(n%siz==cur)return true;
             for(ll c:cb){
                    if(v+c>=k&&chmin(dp[(v+c)%siz],v+c)){
                           pq.emplace(dp[(v+c)%siz],(v+c)%siz);
                    }
             }
      }
      return false;
}
int main(){
     cin>>k>>n;
     a.resize(k);b.resize(k);
     for(int i=0;i<k;i++)cin>>a[i];
     for(int i=0;i<k;i++)cin>>b[i];
     V<ll> cp=a;
     for(int i=0;i<k;i++)cp.emplace_back(b[i]);
     sort(all(cp));
     if(n<k){
           cout<<a[n]<<"\n";
           return 0;
     }
     int l=0,r=2*k;
     while(r-l>1){
            int mid=(l+r)/2;
            if(ok(cp[mid]))l=mid;
            else r=mid;
     }
     cout<<cp[l]<<"\n";
}
0