QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#510693 | #7695. Double Up | 122 | WA | 0ms | 3592kb | C++14 | 883b | 2024-08-09 11:09:37 | 2024-08-09 11:09:37 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
signed main() {
IOS;
int n;
cin >> n;
stack<int> s;
// 先将输入压入栈中
for (int i = 1; i <= n; i++) {
int num;
cin >> num;
s.push(num);
}
stack<int> ss;
int ans = 0;
// 处理栈中数据
while (!s.empty()) {
int num = s.top();
s.pop();
if (ss.empty() || ss.top() > num) {
ss.push(num);
} else {
while (!ss.empty() && ss.top() == num) {
num = 2 * num;
ss.pop();
}
ss.push(num);
}
}
// 计算最大值
while (!ss.empty()) {
ans = max(ans, ss.top());
ss.pop();
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
5 4 2 2 1 8
output:
8
result:
wrong answer 1st lines differ - expected: '16', found: '8'