結果

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

テストケース

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

ソースコード

diff #

//方程式解く必要がなかったな。
#include<iostream>
using namespace std;

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

bool count(int 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);
	}
	return true;
}
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