2 solutions

  • 0
    @ 2024-8-1 11:16:22
    8
    3 7 8 6 5 4 2 1
    
    • 0
      @ 2024-4-20 14:40:59
      #include<bits/stdc++.h>
      using namespace std;
      int a[1010];
      int main()
      {
      	int n;
      	cin>>n;
      	for(int i=1;i<=n;i++)cin>>a[i];
      	stack<int> c;
      	int i=1;
      	for(int j=1;j<=n;j++)
          {
      		c.push(j);
      		while(c.size()&&c.top()==a[i])
              {
      			c.pop();
      			i++;
      		}
      	}
      	if(c.size()==0)cout<<"YES";
      	else cout<<"NO";
      	return 0;
      }
      
      • 1

      Information

      ID
      174
      Time
      1000ms
      Memory
      256MiB
      Difficulty
      3
      Tags
      # Submissions
      17
      Accepted
      6
      Uploaded By