結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,272 KB
testcase_01 AC 4 ms
8,272 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 54 ms
12,904 KB
testcase_07 AC 50 ms
14,348 KB
testcase_08 AC 61 ms
14,348 KB
testcase_09 AC 74 ms
16,080 KB
testcase_10 AC 75 ms
16,080 KB
testcase_11 AC 4 ms
8,400 KB
testcase_12 AC 4 ms
8,400 KB
testcase_13 WA -
testcase_14 AC 4 ms
8,400 KB
testcase_15 AC 4 ms
8,272 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:37:5: warning: control reaches end of non-void function [-Wreturn-type]
   37 |     };
      |     ^

ソースコード

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;}
    };
    int x=up;
    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])
        {
            cur-=f(a[id]+i-1);
            cur+=f(a[id]+i);
        }
        res=min(res,cur);
    }
    cout<<res;
    return 0;
}
0