# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
796154 | 2023-07-28T07:10:20 Z | 박상훈(#10069) | Bitaro's travel (JOI23_travel) | C++17 | 3000 ms | 11256 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; constexpr ll INF = 4e18; ll X[200200]; int main(){ int n; scanf("%d", &n); for (int i=1;i<=n;i++) scanf("%lld", X+i); int q; scanf("%d", &q); while(q--){ int x; scanf("%d", &x); multiset<int> st; for (int i=1;i<=n;i++) st.insert(X[i]); ll ans = 0; int cnt = 0, typ = 0; while(!st.empty()){ auto iter = st.lower_bound(x); ll L = (iter==st.begin())?-INF:*prev(iter); ll R = (iter==st.end())?INF:*iter; if (abs(x-L) <= abs(x-R)){ ans += abs(x-L); x = L; assert(iter!=st.begin()); st.erase(prev(iter)); if (typ==1) cnt++; typ = 0; } else{ ans += abs(x-R); x = R; assert(iter!=st.end()); st.erase(iter); if (typ==0) cnt++; typ = 1; } } assert(cnt < 40); printf("%lld\n", ans); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 69 ms | 11240 KB | Output is correct |
18 | Correct | 63 ms | 11232 KB | Output is correct |
19 | Correct | 58 ms | 11124 KB | Output is correct |
20 | Correct | 61 ms | 11236 KB | Output is correct |
21 | Correct | 59 ms | 11148 KB | Output is correct |
22 | Correct | 64 ms | 11128 KB | Output is correct |
23 | Correct | 71 ms | 11168 KB | Output is correct |
24 | Correct | 59 ms | 11236 KB | Output is correct |
25 | Correct | 62 ms | 11240 KB | Output is correct |
26 | Correct | 61 ms | 11128 KB | Output is correct |
27 | Correct | 64 ms | 11256 KB | Output is correct |
28 | Correct | 60 ms | 11132 KB | Output is correct |
29 | Correct | 59 ms | 11232 KB | Output is correct |
30 | Correct | 59 ms | 11208 KB | Output is correct |
31 | Correct | 62 ms | 11152 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Execution timed out | 3060 ms | 11244 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
3 | Correct | 1 ms | 340 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 1 ms | 340 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 0 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 340 KB | Output is correct |
17 | Correct | 69 ms | 11240 KB | Output is correct |
18 | Correct | 63 ms | 11232 KB | Output is correct |
19 | Correct | 58 ms | 11124 KB | Output is correct |
20 | Correct | 61 ms | 11236 KB | Output is correct |
21 | Correct | 59 ms | 11148 KB | Output is correct |
22 | Correct | 64 ms | 11128 KB | Output is correct |
23 | Correct | 71 ms | 11168 KB | Output is correct |
24 | Correct | 59 ms | 11236 KB | Output is correct |
25 | Correct | 62 ms | 11240 KB | Output is correct |
26 | Correct | 61 ms | 11128 KB | Output is correct |
27 | Correct | 64 ms | 11256 KB | Output is correct |
28 | Correct | 60 ms | 11132 KB | Output is correct |
29 | Correct | 59 ms | 11232 KB | Output is correct |
30 | Correct | 59 ms | 11208 KB | Output is correct |
31 | Correct | 62 ms | 11152 KB | Output is correct |
32 | Correct | 0 ms | 212 KB | Output is correct |
33 | Correct | 0 ms | 212 KB | Output is correct |
34 | Correct | 0 ms | 212 KB | Output is correct |
35 | Correct | 0 ms | 212 KB | Output is correct |
36 | Correct | 0 ms | 212 KB | Output is correct |
37 | Correct | 1 ms | 212 KB | Output is correct |
38 | Execution timed out | 3060 ms | 11244 KB | Time limit exceeded |
39 | Halted | 0 ms | 0 KB | - |