結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 箱星
提出日時 2020-12-09 16:53:40
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,274 bytes
コンパイル時間 329 ms
コンパイル使用メモリ 35,036 KB
最終ジャッジ日時 2025-01-16 20:52:07
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp:4:10: fatal error: testlib.h: No such file or directory
    4 | #include "testlib.h"
      |          ^~~~~~~~~~~
compilation terminated.

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include "testlib.h"
using namespace std;

int main(int argc, char* argv[]) {
    registerValidation(argc, argv);
    int n = inf.readInt(2, 200000, "n");
    inf.readEoln();
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++)
	{
	    a[i] = inf.readInt(1, 1000000000, "a_i");
	    if (i != n - 1) {
            inf.readSpace();
        }
	}
    inf.readEoln();
    inf.readEof();
	vector<bool> is_sorted(n, false);	// a[i],...,a[n-1]がソートされているかどうか
	vector<int> decrease(n, 0);			// a[0],...,a[i]における減少回数
	vector<int> m(n, 0);				// a[0],...,a[i]の最大値
	is_sorted[n - 1] = true;
	for (int i = n - 2; i >= 0; i--) {
		if (a[i] <= a[i + 1])
		{
			is_sorted[i] = true;
		}
		else {
			break;
		}
	}
	if (is_sorted[0])
	{
		cout << 0 << endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		decrease[i] = decrease[i - 1];
		if (a[i - 1] > a[i])
		{
			decrease[i]++;
		}
		m[i] = max(m[i - 1], a[i]);
	}
	for (int i = 0; i < n - 1; i++) {
		if (decrease[i] == 1 && a[i] <= a[0] && is_sorted[i + 1] && m[i] <= a[i + 1])
		{
			cout << 1 << endl;
			return 0;
		}
	}
	if (decrease[n - 1] == 1 && a[n - 1] <= a[0])
	{
		cout << 1 << endl;
		return 0;
	}
	cout << 2 << endl;
}
0