제출 #1111253

#제출 시각아이디문제언어결과실행 시간메모리
1111253StefanSebezRoom Temperature (JOI24_ho_t1)C++14
20 / 100
1 ms592 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ld long double const int inf=1e9; int n,T; ll Plus(ll a,ll b){while(a<0)a+=T;a%=T;while(b<0)b+=T;b%=T;return (a+b)%T;} int Dist(int x,int y){ while(x<0)x+=T;x%=T; while(y<0)y+=T;y%=T; return min(abs(x-y),T-abs(x-y)); } int main(){ scanf("%i%i",&n,&T); int a[2*n+10];for(int i=1;i<=n;i++) scanf("%i",&a[i]),a[i]%=T; sort(a+1,a+n+1); for(int i=1;i<=n;i++) a[i+n]=a[i]; //for(int i=1;i<=n;i++) printf("%i ",a[i]);printf("\n"); int res=0; /*for(int i=1,j=2;i<=n;i++){ while(j<2*n&&Dist(a[i],a[j])<=Dist(a[i],a[j+1]))j++; //printf("%i: %i\n",a[i],a[j]); res=max(res,(Dist(a[i],a[j])+1)/2); }*/ pair<int,int>b[n+10]; ll l=0,r=(T-1)/2; while(l<=r){ ll mid=l+r>>1; vector<pair<int,int>>ev; for(int i=1;i<=n;i++){ int l=Plus(a[i],-mid),r=Plus(a[i],mid); //printf("%i %lld: %i %i\n",a[i],mid,l,r); if(l<=r) ev.pb({l,1}),ev.pb({r+1,-1}); else{ ev.pb({0,1}),ev.pb({r+1,-1}); ev.pb({l,1}),ev.pb({T,-1}); } } sort(ev.begin(),ev.end()); int sum=0;bool bul=false; for(auto i:ev){ sum+=i.se; if(sum==n) bul=true; } if(bul){res=mid;r=mid-1;} else l=mid+1; } printf("%i\n",res); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int Dist(int, int)':
Main.cpp:12:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   12 |  while(x<0)x+=T;x%=T;
      |  ^~~~~
Main.cpp:12:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   12 |  while(x<0)x+=T;x%=T;
      |                 ^
Main.cpp:13:2: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   13 |  while(y<0)y+=T;y%=T;
      |  ^~~~~
Main.cpp:13:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   13 |  while(y<0)y+=T;y%=T;
      |                 ^
Main.cpp: In function 'int main()':
Main.cpp:31:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |   ll mid=l+r>>1;
      |          ~^~
Main.cpp:28:18: warning: unused variable 'b' [-Wunused-variable]
   28 |     pair<int,int>b[n+10];
      |                  ^
Main.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%i%i",&n,&T);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:18:46: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int a[2*n+10];for(int i=1;i<=n;i++) scanf("%i",&a[i]),a[i]%=T;
      |                                         ~~~~~^~~~~~~~~~~~
#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...