Submission #2175803


Source Code Expand

#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int dat[202020];
int main()
{
	int num;
	scanf("%d", &num);
	vector<int>v;
	for (int i = 0; i < num; i++)
	{
		int z;
		scanf("%d", &z);
		z--;
		v.push_back(z);
		int low = lower_bound(v.begin(), v.end(), -z) - v.begin();
		dat[z] = low;
		if (low == v.size())v.push_back(-z);
		else v[low] = -z;
	}
	int ans = 0, bef = -1;
	for (int i = num - 1; i >= 0; i--)
	{
		if (bef == -1)
		{
			if (dat[i] > 0)ans++, bef = i + 1;
		}
		else
		{
			int a = dat[i], b = dat[i + 1], c = dat[bef];
			bool f;
			if (a == b)f = false;
			else if (a == c)f = true;
			else if (int(a < b) + int(b < c) + int(c < a) == 2)f = false;
			else f = true;
			if (f)ans++, bef = i + 1;
		}
	}
	printf("%d\n", ans);
}

Submission Info

Submission Time
Task F - Strange Sorting
User DEGwer
Language C++14 (GCC 5.4.1)
Score 2400
Code Size 810 Byte
Status AC
Exec Time 37 ms
Memory 2168 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:9:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &num);
                   ^
./Main.cpp:14:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &z);
                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 2400 / 2400
Status
AC × 3
AC × 29
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 35 ms 2168 KB
in10.txt AC 35 ms 2168 KB
in11.txt AC 35 ms 2168 KB
in12.txt AC 35 ms 2168 KB
in13.txt AC 36 ms 2168 KB
in14.txt AC 36 ms 2168 KB
in15.txt AC 35 ms 2168 KB
in16.txt AC 35 ms 2168 KB
in17.txt AC 36 ms 2168 KB
in18.txt AC 35 ms 2168 KB
in19.txt AC 36 ms 2168 KB
in2.txt AC 36 ms 2168 KB
in20.txt AC 37 ms 2168 KB
in21.txt AC 25 ms 1912 KB
in22.txt AC 28 ms 1912 KB
in23.txt AC 1 ms 256 KB
in3.txt AC 36 ms 2168 KB
in4.txt AC 37 ms 2168 KB
in5.txt AC 35 ms 2168 KB
in6.txt AC 35 ms 2168 KB
in7.txt AC 35 ms 2168 KB
in8.txt AC 34 ms 2168 KB
in9.txt AC 35 ms 2168 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB