結果

問題 No.1460 Max of Min
ユーザー 👑 Nachia
提出日時 2021-03-31 22:57:50
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,237 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 198,844 KB
最終ジャッジ日時 2025-01-20 04:26:56
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 1 WA * 51 TLE * 39
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |   scanf("%d%llu\n",&K,&N);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:51:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |   rep(i,K) scanf("%lld",&A[i]);
      |            ~~~~~^~~~~~~~~~~~~~
main.cpp:53:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   53 |   rep(i,K) scanf("%lld",&B[i]); reverse(B.begin(),B.end());
      |            ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int GCD(int a,int b){ return b?GCD(b,a%b):a; }

using BinArr = bitset<1000>;

BinArr mask;

int K;
ll N;
vector<ll> A,B;
vector<ll> ValArr;

BinArr precK(BinArr a, BinArr b){
  BinArr res;
  rep(i,K) if(b.test(i)) res|=a>>i;
  BinArr res2;
  rep(i,K) if(b.test(i)) res2|=a<<(K-i);
  return res2 & mask;
}

bool solve(ll x){
  BinArr Ax, Bx;
  rep(i,K) if(A[i]>=x) Ax.set(i);
  rep(i,K) if(B[i]>=x) Bx.set(i);
  if(N/K>=K){
    rep(i,N/K) Ax = precK(Ax,Bx);
    return Ax.test(N%K);
  }
  else{
    int g=0;
    rep(i,K) if(B[i]>=x) g=GCD(K-i,g);
    int p=-1;
    rep(i,K) if(A[i]>=x){
      if(p==-1) p=i; else g=GCD(i-p,g);
    }
    if(p==-1) return false;
    return N%g==p%g;
  }
}

int main(){
  scanf("%d%llu\n",&K,&N);

  rep(i,K) mask.set(i);
  A.resize(K);
  rep(i,K) scanf("%lld",&A[i]);
  B.resize(K);
  rep(i,K) scanf("%lld",&B[i]); reverse(B.begin(),B.end());
  rep(i,K) ValArr.push_back(A[i]);
  rep(i,K) ValArr.push_back(B[i]);
  int l=0, r=ValArr.size()+1;
  while(r-l>1){
    int m=(l+r)/2;
    if(solve(ValArr[m])) l=m; else r=m;
  }
  printf("%lld\n",ValArr[l]);
  return 0;
}

0