제출 #1273257

#제출 시각아이디문제언어결과실행 시간메모리
1273257nlhuyStove (JOI18_stove)C++20
0 / 100
1 ms568 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define Task "test" typedef pair<int,int>ii; const int MOD = 1e9+7; const int INF = 1e9+7; const int Maxn = 1e5+7; const int di[] = {0, 0, -1, 1}; const int dj[] = {-1, 1, 0, 0}; int n,k; int sum; int a[Maxn]; bool check(int x){ int d=k; sum=0; for(int i=1;i<=n;i++){ if (d==0) return false; int ed=a[i]+x; int l=i,r=n,pos=i; while(l<=r){ int g=(l+r)/2; if (a[g]+1<=ed) pos=g,l=g+1; else r=g-1; } sum+=a[pos]+1-a[i]; i=pos; d--; } return true; } void run_case(){ cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; int l=1,r=a[n],ans; while(l<=r){ int g=(l+r)/2; if (check(g)) ans=sum,r=g-1; else l=g+1; } cout<<ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen(Task ".inp", "r")) { freopen(Task ".inp", "r", stdin); freopen(Task ".out", "w", stdout); } int t = 1; //cin >> t; while(t--){ run_case(); } }

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

stove.cpp: In function 'int main()':
stove.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(Task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(Task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...