Submission #1275011

#TimeUsernameProblemLanguageResultExecution timeMemory
1275011muhammad-mutahirRoom Temperature (JOI24_ho_t1)C++20
70 / 100
2095 ms584 KiB
#include <bits/stdc++.h>
using namespace std;

#define print(l) for(auto i:l) cout<<i<<" ";cout<<endl;
#define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i];
#define int long long
#define pb push_back
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define all(l) l.begin(),l.end()
#define pii pair<int,int>
#define fi first
#define se second

const int M = 998244853;

int inf = 1e18;

void io(){
    #ifndef ONLINE_JUDGE
    freopen("input.in","r",stdin);
    // freopen("outputf.in","w",stdout);
    #endif

    ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE
    cin.tie(0), cout.tie(0);
    cout << fixed<<setprecision(9);

}

int n,T;

void solve(){
     cin>>n>>T;
     input(int,l,n);
    sort(all(l));
    int an = 1e18;
    for(int j = -T;j<=T;j++){
         vector<int>l1 = l;
         for(int &i:l){
            i-=j;
         }
         for(int &i:l){
            if(i%T < abs(i%T-T)){
                i%=T;
            }
            else{
                i%=T;
                i-=T;
            }
         }
         int ans = 0;
         for(int i:l){
            ans=max(ans,abs(i));
         }
         an = min(an,ans);
         l = l1;
     }
     cout<<an<<endl;
     //  if(n == 2){
     //     int x1,x2;
     //     if(l[0]%T <= l[1]%T){
     //         x1 = l[0] + (l[1]%T-l[0]%T);
     //         x2 = x1-T;
     //     }
     //     else{
     //         x1 = l[0] + (l[1]%T-l[0]%T);
     //         x2 = x1+T;
     //     }
     //     // cout<<x1<<" "<<x2<<endl;
     //     cout<<min((abs(l[0]-x1)+1)/2,(abs(l[0]-x2)+1)/2)<<endl;;
     //     return;
     //  }
     //    int ans = 1e18;
     // for(int i = 1;i<=T;i++){
     //    int an = -1e18;
     //    for(int j:l){
     //        if(j >= i){
     //        int x1,x2;
     //        if(i%T <= j%T){
     //            x1
     //             = i + (j%T-i%T);
     //            x2 = x1-T;
     //        }
     //        else{
     //            x1 = i + (j%T-i%T);
     //            x2 = x1+T;
     //        }
     //            an = max(an,min({abs(i-x1),abs(i-x2)}));
     //        }
     //        else{
     //            an = max(an,abs(i-j));
     //        }

     //    }
     //    ans = min(ans,an);
     //    an = 0;
     // }
     // cout<<ans<<endl;
}






signed main(){
    // io();
    int t = 1;

    while(t--) solve();

}

Compilation message (stderr)

Main.cpp: In function 'void io()':
Main.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen("input.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...