提出 #60107109


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define edl cout << '\n';
#define vct vector
#define pb push_back
#define pii pair<int, int> 
#define pll pair<ll, ll>
#define fi first
#define se second
#define que queue
#define stk stack
#define sct struct
#define str string
#define rep(i, l, r) for (int i = l; i <= r; i ++)
const int N = 2e5 + 10;
//const int mod 
int a[N];
int cnt[N];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int n;
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	int maxx = 0;
	int l = 1, r = 0;
	while (l < n && r <= n) {
//		cout << l << ' ' << r << '\n';
//		cout << cnt[1] << ' ' << cnt[2] << ' ' << cnt[3] << '\n';
//		if (l == 5 && r == 4) rep(i, 1, n) cout << cnt[a[]] 
		if (r + 2 <= n && a[r+1]==a[r+2] && !cnt[a[r+1]]) {
			cnt[a[r+1]] += 2;
			r += 2;
		} else {
//			cout << "*";
			maxx = max(maxx, r - l + 1);
			if (a[r+1]!=a[r+2] && r + 2 <= n) {//防止数组越界 
//			cout << '&';
				while (l <= r) {
					cnt[l++]--;
				}
				l += 2;
				r = l - 1;
			} else if (cnt[a[r+1]]){
				do {
					cnt[a[l]] -= 2;
					l += 2;
				}while (a[l-1] != a[r+1]) ;
			} else {
//				cout << '(';
				break;
			}
			
		}
	} 
	memset(cnt, 0, sizeof cnt);
	l = 2, r = 1;
	while (l < n && r <= n) {
//		cout << l << ' ' << r << '\n';
//		cout << cnt[1] << ' ' << cnt[2] << ' ' << cnt[3] << '\n';
//		if (l == 5 && r == 4) rep(i, 1, n) cout << cnt[a[]] 
		if (r + 2 <= n && a[r+1]==a[r+2] && !cnt[a[r+1]]) {
			cnt[a[r+1]] += 2;
			r += 2;
		} else {
//			cout << "*";
			maxx = max(maxx, r - l + 1);
			if (a[r+1]!=a[r+2] && r + 2 <= n) {//防止数组越界 
//			cout << '&';
				while (l <= r) {
					cnt[l++]--;
				}
				l += 2;
				r = l - 1;
			} else if (cnt[a[r+1]]){
				do {
					cnt[a[l]] -= 2;
					l += 2;
				}while (a[l-1] != a[r+1]) ;
			} else {
//				cout << '(';
				break;
			}
			
		}
	} 
	cout << maxx;
	return 0;
}

提出情報

提出日時
問題 D - 1122 Substring
ユーザ duanzx
言語 C++ 20 (gcc 12.2)
得点 0
コード長 2061 Byte
結果 RE
実行時間 89 ms
メモリ 5180 KiB

ジャッジ結果

セット名 Sample All after_contest
得点 / 配点 0 / 0 0 / 425 0 / 0
結果
AC × 3
AC × 27
WA × 3
RE × 9
AC × 19
WA × 1
セット名 テストケース
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
after_contest after_contest_00.txt, after_contest_01.txt, after_contest_02.txt, after_contest_03.txt, after_contest_04.txt, after_contest_05.txt, after_contest_06.txt, after_contest_07.txt, after_contest_08.txt, after_contest_09.txt, after_contest_10.txt, after_contest_11.txt, after_contest_12.txt, after_contest_13.txt, after_contest_14.txt, after_contest_15.txt, after_contest_16.txt, after_contest_17.txt, after_contest_18.txt, after_contest_19.txt
ケース名 結果 実行時間 メモリ
after_contest_00.txt AC 1 ms 4184 KiB
after_contest_01.txt AC 1 ms 4196 KiB
after_contest_02.txt AC 6 ms 4772 KiB
after_contest_03.txt AC 6 ms 4720 KiB
after_contest_04.txt AC 4 ms 4420 KiB
after_contest_05.txt AC 3 ms 4500 KiB
after_contest_06.txt AC 10 ms 5108 KiB
after_contest_07.txt AC 1 ms 4172 KiB
after_contest_08.txt AC 1 ms 4316 KiB
after_contest_09.txt AC 7 ms 4712 KiB
after_contest_10.txt AC 1 ms 4248 KiB
after_contest_11.txt WA 10 ms 4892 KiB
after_contest_12.txt AC 11 ms 5020 KiB
after_contest_13.txt AC 11 ms 5016 KiB
after_contest_14.txt AC 10 ms 5052 KiB
after_contest_15.txt AC 1 ms 4388 KiB
after_contest_16.txt AC 1 ms 4248 KiB
after_contest_17.txt AC 1 ms 4124 KiB
after_contest_18.txt AC 1 ms 4132 KiB
after_contest_19.txt AC 1 ms 4328 KiB
example_00.txt AC 1 ms 4196 KiB
example_01.txt AC 1 ms 4200 KiB
example_02.txt AC 1 ms 4264 KiB
hand_00.txt AC 11 ms 5104 KiB
hand_01.txt AC 12 ms 4976 KiB
hand_02.txt AC 10 ms 5176 KiB
hand_03.txt AC 11 ms 5052 KiB
hand_04.txt AC 10 ms 5048 KiB
hand_05.txt AC 2 ms 4264 KiB
random_00.txt AC 11 ms 5040 KiB
random_01.txt WA 11 ms 5108 KiB
random_02.txt WA 11 ms 5052 KiB
random_03.txt WA 12 ms 5036 KiB
random_04.txt RE 89 ms 4880 KiB
random_05.txt RE 88 ms 4748 KiB
random_06.txt RE 87 ms 4744 KiB
random_07.txt RE 86 ms 4740 KiB
random_08.txt RE 85 ms 4780 KiB
random_09.txt RE 88 ms 4760 KiB
random_10.txt AC 11 ms 4972 KiB
random_11.txt AC 11 ms 4988 KiB
random_12.txt AC 11 ms 5032 KiB
random_13.txt AC 11 ms 5104 KiB
random_14.txt RE 88 ms 4744 KiB
random_15.txt AC 11 ms 5052 KiB
random_16.txt AC 10 ms 5020 KiB
random_17.txt AC 11 ms 5048 KiB
random_18.txt AC 11 ms 5180 KiB
random_19.txt AC 11 ms 4916 KiB
random_20.txt AC 11 ms 4948 KiB
random_21.txt AC 11 ms 4960 KiB
random_22.txt AC 11 ms 5180 KiB
random_23.txt RE 88 ms 4784 KiB
random_24.txt AC 11 ms 5016 KiB
random_25.txt RE 87 ms 4744 KiB
random_26.txt AC 11 ms 4952 KiB
random_27.txt AC 11 ms 4976 KiB
random_28.txt AC 11 ms 4916 KiB
random_29.txt AC 12 ms 4956 KiB