/ SeriousOJ /

Record Detail

Compile Error

foo.cc: In function 'int main()':
foo.cc:19:53: error: expected ')' before ';' token
   19 |                         ans.push_back(min(a[l],a[r]);
      |                                      ~              ^
      |                                                     )
foo.cc:20:49: error: expected ')' before ';' token
   20 |                     ans.push_back(max(a[l],a[r]);
      |                                  ~              ^
      |                                                 )
foo.cc:24:32: error: 'class std::vector<int>' has no member named 'pb'
   24 |                            ans.pb(a[l]);
      |                                ^~
foo.cc:28:32: error: 'class std::vector<int>' has no member named 'pb'
   28 |                            ans.pb(a[r]);
      |                                ^~
foo.cc:32:44: error: expected ';' before 'cout'
   32 |         if(is_sorted(ans.begin(),ans.end())cout<<"YES"<<endl;
      |                                            ^~~~
      |                                            ;
foo.cc:33:20: error: expected primary-expression before 'else'
   33 |                    else cout<<"NO"<<endl;
      |                    ^~~~
foo.cc:32:62: error: expected ')' before 'else'
   32 |         if(is_sorted(ans.begin(),ans.end())cout<<"YES"<<endl;
      |           ~                                                  ^
      |                                                              )
   33 |                    else cout<<"NO"<<endl;
      |                    ~~~~                                       

Code

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int t;cin>>t;
	while(t--){
		int n;cin>>n;
		vector<int>a(n),ans;
		for(int i=0;i<n;i++)cin>>a[i];
		if(n==1){
			cout<<"YES"<<endl;
			continue;
		}
		int l=0,r=n-1;
		while(l<r){
		   if(l+1==r){
			ans.push_back(min(a[l],a[r]);
		    ans.push_back(max(a[l],a[r]);
						  break;
		   }
	       if(a[l]<=a[r]){
			   ans.pb(a[l]);
			   l++;
		   }
		   else {
			   ans.pb(a[r]);
			   r--;
		   }
		}
        if(is_sorted(ans.begin(),ans.end())cout<<"YES"<<endl;
		   else cout<<"NO"<<endl;
	}
}

Information

Submit By
Type
Pretest
Problem
P1229 Array of Beauty
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 17:48:32
Judged At
2025-09-02 17:48:32
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes