Submission #691339

#TimeUsernameProblemLanguageResultExecution timeMemory
691339guagua0407Growing Vegetables is Fun 4 (JOI21_ho_t1)C++17
100 / 100
43 ms6952 KiB
/* 燒雞 燒雞 燒雞 好想進選訓 燒雞 燒雞 */ #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int main() {_ //setIO("wayne"); int n; cin>>n; int num[n+1]; for(int i=1;i<=n;i++){ cin>>num[i]; } int dif[n+1]; for(int i=2;i<=n;i++){ dif[i]=num[i]-num[i-1]; } ll pre[n+1],suf[n+1]; pre[1]=0; for(int i=2;i<=n;i++){ pre[i]=pre[i-1]; if(dif[i]<=0){ pre[i]+=-1*dif[i]+1; } } suf[n]=0; for(int i=n-1;i>=1;i--){ suf[i]=suf[i+1]; if(dif[i+1]>=0){ suf[i]+=dif[i+1]+1; } } ll ans=1e18; for(int i=1;i<=n;i++){ ans=min(ans,max(pre[i],suf[i])); } cout<<ans; return 0; } //maybe its multiset not set

Compilation message (stderr)

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...