結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ramia777ramia777
提出日時 2022-04-24 13:43:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 1,788 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 92,920 KB
実行使用メモリ 12,052 KB
最終ジャッジ日時 2024-04-30 17:51:06
合計ジャッジ時間 1,689 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,288 KB
testcase_01 AC 4 ms
11,284 KB
testcase_02 AC 4 ms
11,284 KB
testcase_03 AC 4 ms
11,300 KB
testcase_04 AC 5 ms
11,316 KB
testcase_05 AC 4 ms
11,308 KB
testcase_06 AC 4 ms
11,236 KB
testcase_07 AC 4 ms
11,288 KB
testcase_08 AC 4 ms
11,232 KB
testcase_09 AC 4 ms
11,304 KB
testcase_10 AC 4 ms
11,324 KB
testcase_11 AC 5 ms
11,208 KB
testcase_12 AC 4 ms
11,248 KB
testcase_13 AC 4 ms
11,312 KB
testcase_14 AC 4 ms
11,276 KB
testcase_15 AC 20 ms
11,700 KB
testcase_16 AC 19 ms
11,632 KB
testcase_17 AC 20 ms
11,692 KB
testcase_18 AC 30 ms
12,052 KB
testcase_19 AC 20 ms
11,644 KB
testcase_20 AC 12 ms
11,652 KB
testcase_21 AC 8 ms
11,404 KB
testcase_22 AC 15 ms
11,712 KB
testcase_23 AC 10 ms
11,456 KB
testcase_24 AC 27 ms
12,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//
// Yukicoder
// No.3009


//#include "stdafx.h"
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>//list
#include <set> //tree
#include <map> //連想配列
#include <unordered_set> //hash
#include <unordered_map> //hash
#include <algorithm>
#include <iomanip>
#include <string>
#include <stdlib.h>


using namespace std;
typedef unsigned long long ULL;
typedef signed long long SLL;
typedef unsigned int UINT;


#define START (0)
#define RIGHT (1)
#define UP    (2)
#define LEFT  (3)
#define DOWN  (4)

#define DATA_MAX (1000000)
#define FMAX(a,b)  ((a)>(b)?(a):(b))
#define FMIN(a,b)  ((a)<(b)?(a):(b))


vector <vector <SLL>> memo2;//二次元可変配列

vector<SLL> memo1;
vector<SLL> c;
vector<SLL> v;
vector<SLL> dp;

SLL H ,A, B, T, F, N, M, Result;


SLL backet[1000005];

int main(int argc, char *argv[])
{

	SLL a[100005];
	

	cin >> N;
	
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}

	//cout << "-----" << endl;

	SLL L, R, ans=0, max_ans = 0;

	for (int i = 0; i < 1000005; i++)
	{
		backet[i] = -1;
	}


	//Nが1以下のとき
	if (N <= 1)
	{
		cout << N << endl;
		return 0;
	}

	//Nが2以上のとき
	L = 0;
	R = 0;

	do {
			
			//今回の数値が過去の数列に含まれていたら....
			if (backet[a[R]] != -1)
			{			
				// 左側の位置を更新
				if (L <= backet[a[R]])
					L = backet[a[R]]+1;				
			}

			//バケット配列に配列インデックスをいれる
			backet[a[R]] = R;

			if (max_ans < R - L + 1)
				max_ans = R - L + 1;

		//cout << "L=" << L << ",R=" << R << ",ans=" << max_ans << ",backet[a[R]]=" << backet[a[R]] << ",a[R]=" << a[R] << endl;

		//右側は毎回更新
		R++;

	} while (R < N);
	
	cout << max_ans << endl;

	///////////////////
	//cout << endl;
	//getchar();

	return 0; //end
}
0