結果
問題 | No.1156 Nada Picnic 2 |
ユーザー |
![]() |
提出日時 | 2021-01-10 12:01:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 1,375 bytes |
コンパイル時間 | 2,066 ms |
コンパイル使用メモリ | 198,928 KB |
最終ジャッジ日時 | 2025-01-17 15:55:20 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 3 |
ソースコード
#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;}}