5 条题解

  • 1
    @ 2025-10-5 15:48:02

    题目

    #include<bits/stdc++.h>
    using namespace std;
    stack <int> s;
    int a[1005],n;
    int main(){
        cin >> n;
        for(int i=1; i<=n; i++)
            cin >> a[i];
        int t=1;
        for(int i=1; i<=n; i++){
            while(t<=a[i]){
                s.push(t);
                t++;
            }
            if(s.top()==a[i]) s.pop();
            else{
                cout << "NO";
                return 0;
            }
        }
        cout << "YES";
        return 0;
    }
    

    信息

    ID
    3047
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    递交数
    417
    已通过
    94
    上传者