結果

問題 No.1156 Nada Picnic 2
ユーザー tkmst201tkmst201
提出日時 2021-01-10 12:01:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 2,379 ms
コンパイル使用メモリ 206,824 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-30 22:01:51
合計ジャッジ時間 2,852 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	--N;
	vector<int> a[3] {{0, 1, 2}, {0, 0, 1, 2}, {0, 1, 2, 3, 4, 5}};
	vector<int> b[3] {{3, 4, 5}, {3, 4, 5, 6}, {6, 3, 5, 7, 8}};
	vector<int> c[3] {{1, 6, 2, 1}, {7, 8, 1, 2, 9}, {1, 3, 9, 4, 3, 9}};
	vector<int> ord(10); // ord[i] := i に対応する数字
	iota(ALL(ord), 0);
	while (next_permutation(ALL(ord))) {
		int na = 0, nb = 0;
		if (ord[a[N][0]] == 0 || ord[b[N][0]] == 0) continue;
		REP(i, a[N].size()) { na *= 10; na += ord[a[N][i]]; }
		REP(i, b[N].size()) { nb *= 10; nb += ord[b[N][i]]; }
		int nc = na + nb;
		string sc = to_string(nc);
		if (sc.size() != c[N].size()) continue;
		bool ng = false;
		REP(i, c[N].size()) ng |= sc[i] - '0' != ord[c[N][i]];
		if (ng) continue;
		cout << nc << endl;
		return 0;
	}
}
0