結果

問題 No.1156 Nada Picnic 2
ユーザー k
提出日時 2020-11-06 21:18:21
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,348 bytes
コンパイル時間 2,389 ms
コンパイル使用メモリ 209,872 KB
最終ジャッジ日時 2025-01-15 20:06:27
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 RE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int solve(std::string, std::string, std::string)’:
main.cpp:47:1: warning: control reaches end of non-void function [-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