結果

問題 No.112 ややこしい鶴亀算
ユーザー startcppstartcpp
提出日時 2015-02-23 14:41:29
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 988 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 51,508 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-06 03:03:42
合計ジャッジ時間 1,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int n;
int a[51];
int turu, kame;

bool count(int t) {
	int tmp = t;
	turu = 0; kame = 0;
	for( int i = 0; i < n; i++ ) {
		if ( t == 2 ) turu++;
		else if ( t == 4 ) kame++;
		else return false;
		t = -(a[i+1] - a[i] - t);
	}
	//最後に0番目の動物の足の本数が矛盾していないかも確かめる!!
	if ( t == tmp ) return true;
	return false;
}
int main() {
	cin >> n;
	for( int i = 0; i < n; i++ )
		cin >> a[i];
	
	//a[i+1]-a[i] = i番目の動物の足の本数 - i+1番目の動物の足の本数
	//0番目の動物の足の本数(鶴orカメ)を決めれば、そのあとは一意(であり矛盾するかどうかはO(N)で分かる)
	//矛盾しないルートを選択して、このときの各動物の足のから、各動物が鶴か亀かを判定する。最後にカウント。
	
	if ( count(2) ) { cout << turu << " " << kame << endl; return 0; }
	count(4);
	cout << turu << " " << kame << endl; return 0;
}
0