UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214948#3856. 排序drdilyor1087ms5444kbC++11786b2024-11-24 12:12:282024-11-24 13:15:46

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
void ts(){cout<<"IAKIOI\n";}
inline int read(){
	int n=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		n=n*10+ch-'0';
		ch=getchar();
	}
	return n*f;
}
int n;
int a[500005];
signed main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	stack<int> stk;
	for(int i=1;i<=n;i++){
		if(stk.empty())stk.push(a[i]);
		else{
			if(a[i]>stk.top())stk.push(a[i]);
			else{
				if(stk.size()==1){
					stk.pop(),stk.push(a[i]);continue;
				}
				int v=stk.top();
				stk.pop();
				if(a[i]>stk.top())stk.push(a[i]);
				else stk.push(v);
			}
		}
	}
	cout<<stk.size()<<"\n";
	return 0;
}
//look at my code
//my code is amazing

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1216kb

input:

475
319 474 473 472 471 183 108 346 43 466 465 464 168 462 461 309 459 458 457 456 455 38 372 312 94...

output:

9

result:

wrong answer 1st numbers differ - expected: '11', found: '9'

Subtask #2:

score: 0
Skipped

Subtask #3:

score: 10
Accepted

Test #9:

score: 10
Accepted
time: 32ms
memory: 5444kb

input:

499758
77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 ...

output:

55744

result:

ok 1 number(s): "55744"

Test #10:

score: 0
Accepted
time: 28ms
memory: 5436kb

input:

498773
255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 2...

output:

55362

result:

ok 1 number(s): "55362"

Subtask #4:

score: 0
Wrong Answer

Test #11:

score: 0
Wrong Answer
time: 27ms
memory: 4856kb

input:

466818
447360 121353 327541 289718 71942 242279 307652 438765 78054 253024 190170 21720 292462 72832...

output:

23

result:

wrong answer 1st numbers differ - expected: '32', found: '23'

Subtask #5:

score: 0
Skipped