結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ramia777ramia777
提出日時 2022-04-24 12:04:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,992 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 94,928 KB
実行使用メモリ 12,308 KB
最終ジャッジ日時 2023-09-03 17:01:35
合計ジャッジ時間 1,887 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 26 ms
11,708 KB
testcase_16 AC 24 ms
11,876 KB
testcase_17 WA -
testcase_18 AC 36 ms
12,308 KB
testcase_19 AC 27 ms
11,804 KB
testcase_20 AC 18 ms
11,484 KB
testcase_21 AC 13 ms
11,504 KB
testcase_22 AC 19 ms
11,512 KB
testcase_23 AC 14 ms
11,384 KB
testcase_24 AC 26 ms
5,512 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;

UINT hashtable;


SLL hashTable[1000005];

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

	SLL a[100005];
	

	cin >> N;
	v.resize(N + 1);

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

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

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


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


	//Nが2以上のとき
	const int search_complete = 1;
	const int search_break = 0;
	int flag;
	SLL i;

	L = 0;
	R = L;

	flag = search_complete;

	do {
		   
			if (hashTable[a[R]] == 0)
			{
				//バケット配列にインデックスをいれる(インデックス0と何もないの0を区別するために1から始める)
				hashTable[a[R]] = R+1;

				if (max_ans < R - L + 1 )
					max_ans = R - L + 1;
			}
			else
			{
				
				flag = search_break;
			}


		//cout << "L=" << L << ",R=" << R << ",ans=" << max_ans << endl;

		if (flag == search_break)
		{
			ans = 0;

			if(L < hashTable[a[R]])
				L = hashTable[a[R]]; //予め+1しているのでそのまま入れる

			hashTable[a[R]] = R+1;
			
			flag = search_complete;
		}

		R++;

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

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

	return 0; //end
}
0