Submission #1112877

#TimeUsernameProblemLanguageResultExecution timeMemory
1112877duyhoanhoReal Mountains (CCO23_day1problem2)C++17
0 / 25
1 ms336 KiB
#include<bits/stdc++.h> #define int long long #define pii pair<int,int> #define fi first #define se second using namespace std; const int N = 5e3 + 10 ,M = 1e6 + 3; int n , h[N]; int peak,ans,cnt[N] , sum[N]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); #define task "task" if(fopen(task".inp","r")) { freopen(task".inp","r",stdin); freopen(task".out","w",stdout); } if(fopen("task.inp","r")) { freopen("task.inp","r",stdin); freopen("task.out","w",stdout); } cin >> n; for(int i = 1; i <=n;i++) sum[i] = i + sum[i - 1]; for(int i = 1; i <= n; i++) cin >> h[i] , cnt[h[i]]++; for(int i = 1; i < n;i++){ if(h[i + 1] > h[i]){ peak = i; break; } } if(peak == 0) peak = n; int l = peak; int r = peak; while(true){ while(h[l] <= h[peak] && l > 0) l--; while(h[r] <= h[peak] && r <= n) r++; if(l == 0 || r == n + 1){ cout<<ans; return 0; } int tmp = min(h[l] , h[r]); ans = (ans + (tmp - h[peak]) * (h[l] + h[r]) * cnt[h[peak]]) % M; ans = (ans + (sum[tmp - 1] - sum[h[peak] - 1]) * cnt[h[peak]]) % M; if(h[l] <= h[r]) cnt[h[l]]+=cnt[h[peak]]; else cnt[h[r]]+=cnt[h[peak]]; h[peak] = tmp; } }

Compilation message (stderr)

Main.cpp: In function 'int32_t main()':
Main.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen("task.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...