結果

問題 No.2627 Unnatural Pitch
ユーザー maksimmaksim
提出日時 2024-02-09 21:50:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 4,000 ms
コード長 1,521 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 176,484 KB
実行使用メモリ 16,592 KB
最終ジャッジ日時 2024-02-09 21:50:52
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,272 KB
testcase_01 AC 3 ms
8,272 KB
testcase_02 AC 3 ms
8,272 KB
testcase_03 AC 3 ms
8,272 KB
testcase_04 AC 57 ms
12,904 KB
testcase_05 AC 59 ms
12,904 KB
testcase_06 AC 53 ms
12,904 KB
testcase_07 AC 49 ms
14,348 KB
testcase_08 AC 57 ms
14,348 KB
testcase_09 AC 86 ms
16,080 KB
testcase_10 AC 73 ms
16,080 KB
testcase_11 AC 4 ms
8,400 KB
testcase_12 AC 4 ms
8,400 KB
testcase_13 AC 3 ms
8,272 KB
testcase_14 AC 4 ms
8,400 KB
testcase_15 AC 3 ms
8,272 KB
testcase_16 AC 90 ms
15,440 KB
testcase_17 AC 118 ms
16,592 KB
testcase_18 AC 84 ms
14,800 KB
testcase_19 AC 103 ms
15,952 KB
testcase_20 AC 37 ms
10,832 KB
testcase_21 AC 51 ms
12,240 KB
testcase_22 AC 87 ms
14,672 KB
testcase_23 AC 46 ms
11,984 KB
testcase_24 AC 54 ms
12,496 KB
testcase_25 AC 62 ms
12,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define app push_back
#ifdef LOCAL
#define debug(...) [](auto...a){ ((cout << a << ' '), ...) << '\n';}(#__VA_ARGS__, ":", __VA_ARGS__)
#else
#define debug(...)
#endif
const int inf=1e18;
const int maxn=2e5+5;
vector<int> inter[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k,l,u;cin>>n>>k>>l>>u;
    int a[n];for(int i=0;i<n;++i) cin>>a[i]; sort(a,a+n);
    int low=(-inf);int up=inf;
    while(up-low>1)
    {
        int mid=(low+up)/2;
        int c1=0,c2=0;
        for(int i=0;i<n;++i)
        {
            if(a[i]+mid>=u-k+1) {++c2;}
            else if(a[i]+mid<=l-1) {++c1;}
        }
        if(c2>=c1) up=mid;
        else low=mid;
    }
    auto f=[&](int x)->int
    {
        if(x<l) {return (l-x+k-1)/k;}
        else if(x>u) {return (x-u+k-1)/k;}
        return 0;
    };
    int x=up;
    debug(x);
    for(int i=0;i<n;++i) {a[i]+=x;}
    int cur=0;for(int i=0;i<n;++i) {cur+=f(a[i]);}
    int res=cur;
    for(int i=0;i<n;++i)
    {
        inter[((l-a[i])%k+k)%k].app(i);
        inter[((u+1-a[i])%k+k)%k].app(i);
    }
    for(int i=0;i<k;++i) {sort(all(inter[i]));inter[i].erase(unique(all(inter[i])),inter[i].end());}
    for(int i=1;i<k;++i)
    {
        for(int id:inter[i])
        {
            debug(i,id);
            cur-=f(a[id]+i-1);
            cur+=f(a[id]+i);
        }
        res=min(res,cur);
    }
    cout<<res;
    return 0;
}
0