結果

問題 No.1597 Matrix Sort
ユーザー ironairona
提出日時 2021-07-10 11:15:21
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 1,500 ms
コード長 1,153 bytes
コンパイル時間 3,823 ms
コンパイル使用メモリ 229,424 KB
実行使用メモリ 82,912 KB
最終ジャッジ日時 2023-09-14 18:49:19
合計ジャッジ時間 7,685 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 144 ms
82,764 KB
testcase_04 AC 149 ms
82,668 KB
testcase_05 AC 145 ms
82,620 KB
testcase_06 AC 143 ms
82,692 KB
testcase_07 AC 143 ms
82,728 KB
testcase_08 AC 138 ms
82,616 KB
testcase_09 AC 139 ms
82,720 KB
testcase_10 AC 95 ms
82,668 KB
testcase_11 AC 106 ms
82,664 KB
testcase_12 AC 65 ms
4,692 KB
testcase_13 AC 90 ms
12,284 KB
testcase_14 AC 144 ms
82,688 KB
testcase_15 AC 60 ms
4,784 KB
testcase_16 AC 82 ms
12,444 KB
testcase_17 AC 119 ms
82,912 KB
testcase_18 AC 137 ms
82,788 KB
testcase_19 AC 127 ms
82,624 KB
testcase_20 AC 113 ms
82,720 KB
testcase_21 AC 107 ms
82,768 KB
testcase_22 AC 101 ms
82,756 KB
testcase_23 AC 97 ms
82,696 KB
testcase_24 AC 37 ms
4,716 KB
testcase_25 AC 34 ms
4,716 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 33 ms
81,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include <atcoder/all>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>
#define pll pair<ll,ll>
#define count __builtin_popcountll

using namespace std;
using namespace atcoder;
//using mint = modint1000000007;

const ll mod=1000000007;//998244353;
const ll inf=1000000000000000000;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){
  cout << fixed << setprecision(15);

  ll n,k,p;
  cin >> n >> k >> p;
  vec a(n),b(n);
  for(ll i=0;i<n;i++)cin >> a[i];
  for(ll i=0;i<n;i++)cin >> b[i];
  for(ll i=0;i<n;i++){
    a[i]%=p;
    b[i]%=p;
  }
  


  sort(a.begin(),a.end());
  sort(b.begin(),b.end());


  vec s(p+1);
  for(ll i=0;i<n;i++){
    s[b[i]]++;
  }
  for(ll i=0;i<p-1;i++){
    s[i+1]+=s[i];
  }

  ll l=-1,r=p,h=(r+l)/2;

  while(abs(r-l)>1){
    ll ret=0;
    for(ll i=0;i<n;i++){
      if(a[i]<=h){
        ret+=s[h-a[i]];
        ret+=n-s[p-a[i]-1];
      }
      else{
        ret+=s[h-a[i]+p]-s[p-a[i]-1];
      }
    }
    if(ret>=k)r=h;
    else l=h;
    h=(r+l)/2;
  }

  cout << r << endl;
  

  return 0;
}
0