結果

問題 No.1156 Nada Picnic 2
ユーザー kk
提出日時 2020-11-06 21:18:21
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,348 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 214,340 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 18:00:41
合計ジャッジ時間 3,702 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,380 KB
testcase_01 AC 27 ms
4,380 KB
testcase_02 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int solve(std::string, std::string, std::string)’ 内:
main.cpp:47:1: 警告: 制御が非 void 関数の終りに到達しました [-Wreturn-type]
   47 | }
      | ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int conv(const vector<int> &xs, const vector<int> &v) {
  int r = 0;
  if (xs.size() > 1 && v[xs[0]] == 0)
    return -1;
  for (int x: xs)
    r = r * 10 + v[x];
  return r;
}

int solve(string x, string y, string z) {
  set<char> st;
  for (char c: x) st.insert(c);
  for (char c: y) st.insert(c);
  for (char c: z) st.insert(c);

  map<char, int> enc;
  int t = 0;
  for (char c: st) 
    enc[c] = t++;

  vector<int> v;
  REP (i, 10) v.push_back(i);

  vector<int> xx, yy, zz;
  for (char c: x) xx.push_back(enc[c]);
  for (char c: y) yy.push_back(enc[c]);
  for (char c: z) zz.push_back(enc[c]);
  
  do {
    int nx = conv(xx, v);
    int ny = conv(yy, v);
    int nz = conv(zz, v);
    if (nx == -1 || ny == -1 || nz == -1) continue;
    if (nx + ny == nz)
      return nz;
  } while (next_permutation(v.begin(), v.end()));
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  cin >> n;
  if (n == 1)
    cout << solve("abc", "def", "bgcb") << endl;
  else if (n == 2)
    cout << solve("aabc", "defg", "hibcj") << endl;
  else
    cout << solve("spring", "eight", "panic") << endl;
  
  return 0;
}
0