# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1112877 | 2024-11-15T07:00:20 Z | duyhoanho | Real Mountains (CCO23_day1problem2) | C++17 | 1 ms | 336 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Incorrect | 1 ms | 336 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |