結果

問題 No.1053 ゲーミング棒
コンテスト
ユーザー QCFium
提出日時 2020-05-15 22:22:54
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 771 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 942 ms
コンパイル使用メモリ 186,248 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-07 21:39:12
合計ジャッジ時間 1,808 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:19:31: warning: 'void* __builtin_memset(void*, int, long unsigned int)' specified size between 18446744065119617024 and 18446744073709551612 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   19 |         for (auto &i : cnt) i = -1;
      |                             ~~^~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri() - 1;
	
	std::vector<int> compressed;
	for (int i = 0; i < n; i++) if (!i || a[i - 1] != a[i]) compressed.push_back(a[i]);
	
	bool possible = true;
	int cnt[n];
	for (auto &i : cnt) i = -1;
	std::vector<int> twos;
	for (int i = 0; i < (int) compressed.size(); i++) {
		if (cnt[compressed[i]] == -2) possible = false;
		else if (cnt[compressed[i]] == -1) cnt[compressed[i]] = i;
		else twos.push_back(i), twos.push_back(cnt[compressed[i]]), cnt[compressed[i]] = -2;
	}
	for (auto i : twos) if (i && i + 1 < (int) compressed.size()) possible = false;
	
	printf("%s\n\n", possible ? twos.size() ? "1" : "0" : "-1");
	
	return 0;
}
0