結果
問題 | No.1597 Matrix Sort |
ユーザー | yunix91201367 |
提出日時 | 2021-07-09 22:17:53 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 286 ms / 1,500 ms |
コード長 | 1,300 bytes |
コンパイル時間 | 1,554 ms |
コンパイル使用メモリ | 168,904 KB |
実行使用メモリ | 82,912 KB |
最終ジャッジ日時 | 2023-09-14 09:32:19 |
合計ジャッジ時間 | 7,085 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 264 ms
82,764 KB |
testcase_04 | AC | 278 ms
82,748 KB |
testcase_05 | AC | 286 ms
82,572 KB |
testcase_06 | AC | 266 ms
82,708 KB |
testcase_07 | AC | 255 ms
82,760 KB |
testcase_08 | AC | 214 ms
82,764 KB |
testcase_09 | AC | 236 ms
82,708 KB |
testcase_10 | AC | 138 ms
82,632 KB |
testcase_11 | AC | 146 ms
82,588 KB |
testcase_12 | AC | 81 ms
4,584 KB |
testcase_13 | AC | 126 ms
12,308 KB |
testcase_14 | AC | 274 ms
82,708 KB |
testcase_15 | AC | 84 ms
4,708 KB |
testcase_16 | AC | 117 ms
12,352 KB |
testcase_17 | AC | 182 ms
82,892 KB |
testcase_18 | AC | 235 ms
82,636 KB |
testcase_19 | AC | 186 ms
82,636 KB |
testcase_20 | AC | 167 ms
82,568 KB |
testcase_21 | AC | 168 ms
82,912 KB |
testcase_22 | AC | 170 ms
82,684 KB |
testcase_23 | AC | 155 ms
82,784 KB |
testcase_24 | AC | 34 ms
4,700 KB |
testcase_25 | AC | 32 ms
4,764 KB |
testcase_26 | AC | 1 ms
4,376 KB |
testcase_27 | AC | 1 ms
4,376 KB |
testcase_28 | AC | 1 ms
4,384 KB |
testcase_29 | AC | 35 ms
81,196 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; // using P = pair<int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int calc(vec_int &imos, int left, int right){ if(left==0)return imos.at(right); return imos.at(right)-imos.at(left-1); } int count(vec_int &A, vec_int &imos, int mid, int P){ int num = 0; int N = A.size(); for(int i=0;i<N;i++){ int left = (P-A.at(i))%P; int right = (P+mid-A.at(i))%P; if(left<=right){ num += calc(imos, left, right); }else{ num += calc(imos, left, P-1); num += calc(imos, 0, right); } } return num; } signed main(){ int N, K, P; cin>>N>>K>>P; vec_int A(N), B(N); rep(i,N)cin>>A.at(i); rep(i,N)cin>>B.at(i); vec_int imos(P, 0); rep(i,N){ imos.at(B.at(i))++; } for(int i=1;i<P;i++)imos.at(i) += imos.at(i-1); int left = -1; //K以下値 int right = P-1; //K番目より大きい値 while(right>left+1){ int mid = (right+left)/2; int num = count(A, imos, mid, P); if(num<K){ left = mid; }else{ right = mid; } } cout<<right<<endl; return 0; }