結果

問題 No.1687 What the Heck?
ユーザー publflpublfl
提出日時 2021-09-24 21:28:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 50,404 KB
実行使用メモリ 13,280 KB
最終ジャッジ日時 2023-09-18 20:40:48
合計ジャッジ時間 2,882 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 51 ms
6,636 KB
testcase_08 AC 79 ms
8,172 KB
testcase_09 WA -
testcase_10 AC 30 ms
5,420 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 198 ms
13,172 KB
testcase_14 AC 204 ms
13,200 KB
testcase_15 AC 208 ms
13,184 KB
testcase_16 AC 207 ms
13,056 KB
testcase_17 AC 9 ms
4,376 KB
testcase_18 AC 213 ms
13,176 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <set>

int x[200010];
std::set<int> S;
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	for(int i=1;i<=a;i++) S.insert(i);
	
	long long int sum = 0;
	for(int i=a;i>=1;i--)
	{
		std::set<int> ::iterator it = S.lower_bound(x[i]);
		if(it==S.end())
		{
			S.erase(S.begin());
			sum -= i;
		}
		else
		{
			std::set<int> ::iterator it2 = it;
			it2++;
			if((*it)==x[i])
			{
				if(it2==S.end()) S.erase(it);
				else
				{
					S.erase(it2);
					sum += i;
				}
			}
			else
			{
				S.erase(it);
				sum += i;
			}
		}
	}
	
	printf("%lld",sum);
}
0