Submission #1231943

#TimeUsernameProblemLanguageResultExecution timeMemory
1231943clemmy14Room Temperature (JOI24_ho_t1)C++20
70 / 100
2093 ms328 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int n, t; cin >> n >> t;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) a[i]%=t;
    sort(a.begin(), a.end());
    vector<int> cur={a[0]};
    for(int i=1; i<n; i++) if(a[i] != a[i-1]) cur.push_back(a[i]);
    a=cur;
    vector<int> aa;
    for(int i=0; i<a.size(); i++) aa.push_back(a[i]-t);
    for(int i=0; i<a.size(); i++) aa.push_back(a[i]);
    for(int i=0; i<a.size(); i++) aa.push_back(a[i]+t);

    // for(auto x : aa) cout << x << ' ';
    // cout << endl;

    int best=t/2, half=t/2;

    for(int i=0; i<t; i++) {
        auto prev = lower_bound(aa.begin(), aa.end(), i-half), aft = upper_bound(aa.begin(), aa.end(), i+half);
        aft--;
        best=min(best, max(i-aa[prev-aa.begin()], aa[aft-aa.begin()]-i));
    }
    

    //a.push_back(a[0]+t);



    // for(int i=1; i<a.size(); i++) {
    //     int mid1 = (a[i]-a[i-1])/2 + a[i-1], mid2=(a[i]-a[i-1]+1)/2 + a[i-1];

    //     auto prev = lower_bound(aa.begin(), aa.end(), mid1-half), aft = upper_bound(aa.begin(), aa.end(), mid1+half); 
    //     aft--;
    //     best=min(best, max(mid1-aa[prev-aa.begin()], aa[aft-aa.begin()]-mid1));

    //     prev = lower_bound(aa.begin(), aa.end(), mid2-half); aft = upper_bound(aa.begin(), aa.end(), mid2+half);
    //     aft--;
    //     best=min(best, max(mid2-aa[prev-aa.begin()], aa[aft-aa.begin()]-mid2));
    // }

    cout << best;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...