結果

問題 No.1156 Nada Picnic 2
ユーザー forest3forest3
提出日時 2020-12-22 01:37:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,079 bytes
コンパイル時間 1,754 ms
コンパイル使用メモリ 169,864 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 12:21:32
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 16 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N;
	cin >> N;

	int ans = 0;
	if( N == 1 ) ans = 1491;
	else if( N == 2 ) {
		int od[9] = { 0, 2, 3, 4, 5, 6, 7, 8, 9  };
		vector<int> a( od, od + 9 );
		do {
			if( a[4] == 0 || a[5] == 0 ) continue;
			int b = a[4] * 1000 + a[4] * 100 + a[1] * 10 + a[2];
			int c = a[5] * 1000 + a[6] * 100 + a[7] * 10 + a[8];
			int d = 10000 + a[0] * 1000 + a[1] * 100 + a[2] * 10 + a[3];
			if( b + c == d ) {
				ans = d;
				break;
			}
		} while( next_permutation( a.begin(), a.end() ) );
	}
	else {
		int od[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9  };
		vector<int> a( od, od + 10 );
		do {
			if( a[3] == 0 || a[6] == 0 || a[9] == 0 ) continue;
			int b = a[3] * 100000 + a[9] * 10000 + a[4] * 1000 + a[0] * 100 + a[2] * 10 + a[5];
			int c = a[6] * 10000 + a[0] * 1000 + a[5] * 100 + a[7] * 10 + a[8];
			int d = a[9] * 100000 + a[0] * 10000 + a[1] * 1000 + a[2] * 100 + a[0] * 10 + a[1];
			if( b + c == d ) {
				ans = d;
				break;
			}
		} while( next_permutation( a.begin(), a.end() ) );
	}

	cout << ans << endl;
}
0