Skip to content

Commit 3294527

Browse files
committed
atcoder/abc188C (feedback from editorial)
1 parent a3a94b9 commit 3294527

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

atcoder/abc188/C/main.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,25 @@ using namespace std;
44
using ll = int64_t;
55
using ff = long double;
66

7-
int N, M;
8-
vector<int> A;
9-
10-
array<int,2> solve(int tl, int tr) {
11-
if (tr - tl == 2) {
12-
if (A[tl] < A[tl+1]) return { tl, tl+1 };
13-
else return { tl+1, tl };
14-
}
15-
int tm = (tl + tr) >> 1;
16-
auto lhs = solve(tl, tm);
17-
auto rhs = solve(tm, tr);
18-
int l = lhs[1], r = rhs[1];
19-
if (A[l] < A[r]) return { l, r };
20-
else return { r, l };
21-
}
22-
237
int main() {
248
ios_base::sync_with_stdio(false);
259
cin.tie(0); cout.tie(0);
2610

11+
int N, M;
12+
vector<int> A;
13+
2714
cin >> N;
2815
M = 1 << N;
2916
A.assign(M, 0);
3017
for (int i = 0; i < M; ++i) {
3118
cin >> A[i];
3219
}
33-
int ans = solve(0, M)[0] + 1;
34-
cout << ans << endl;
20+
21+
M /= 2;
22+
auto l = distance(A.begin(), max_element(A.begin(), A.begin() + M));
23+
auto r = distance(A.begin(), max_element(A.begin() + M, A.end()));
24+
int ans = (A[l] < A[r]) ? l : r;
25+
cout << (ans+1) << endl;
3526

3627
return 0;
3728
}

0 commit comments

Comments
 (0)