結果
問題 |
No.8009 異なる数字の最大の範囲(勉強会用)
|
ユーザー |
![]() |
提出日時 | 2022-04-24 13:43:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 5,000 ms |
コード長 | 1,788 bytes |
コンパイル時間 | 788 ms |
コンパイル使用メモリ | 94,684 KB |
実行使用メモリ | 11,956 KB |
最終ジャッジ日時 | 2024-11-20 15:08:39 |
合計ジャッジ時間 | 1,856 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
// // 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 }