QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510693#7695. Double Up122WA 0ms3592kbC++14883b2024-08-09 11:09:372024-08-09 11:09:37

Judging History

你现在查看的是最新测评结果

  • [2024-08-09 11:09:37]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-08-09 11:09:37]
  • 提交

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'