QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#723914#7705. Make Your Own Morse Code PalindromeMattTheNub#WA 1ms3836kbC++234.9kb2024-11-08 03:30:392024-11-08 03:30:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 03:30:40]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-11-08 03:30:39]
  • 提交

answer

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

template <class T> using v = vector<T>;
using ll = long long;
using dd = long double;
using int2 = pair<int, int>;
using ll2 = pair<ll, ll>;
using dd2 = pair<dd, dd>;

#define f first
#define s second
#define all(x) begin(x), end(x)
istream &__cin = cin;
#ifdef DEV_MODE
#include "debug.h"
__cinwrapper __cin_wrapper;
#define cin __cin_wrapper
#else
#define dbg(...)
#define dbg2d(...)
#endif

template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
  in >> p.first >> p.second;
  return in;
}
template <class T> istream &operator>>(istream &in, v<T> &v) {
  for (auto &x : v)
    in >> x;
  return in;
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
 _______________________________________
( If you don't fail at least 90% of the )
( time, you're not aiming high enough.  )
(                                       )
( - Alan Kay                            )
 ---------------------------------------
        o   ^__^
         o  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
*/

const bool INTERACTIVE = false;
const bool MULTITEST = false;
/******************************************************************************/

#pragma region templates

#pragma endregion templates

const string code[] = {".-",    "-...",  "-.-.",  "-..",   ".",     "..-.",
                       "--.",   "....",  "..",    ".---",  "-.-",   ".-..",
                       "--",    "-.",    "---",   ".--.",  "--.-",  ".-.",
                       "...",   "-",     "..-",   "...-",  ".--",   "-..-",
                       "-.--",  "--..",  "-----", ".----", "..---", "...--",
                       "....-", ".....", "-....", "--...", "---..", "----."};
string get(char c) {
  if (c >= 'A' && c <= 'Z') {
    return code[c - 'A'];
  } else {
    return code[c - '0' + 26];
  }
}
char unget(int i) {
  if (i < 26)
    return i + 'A';
  else
    return i + '0' - 26;
}

void solve() {
  string s;
  cin >> s;
  string t;
  for (auto x : s) {
    t.append(get(x));
  }

  string r = t;
  reverse(all(r));
  if (t == r) {
    cout << 0;
    return;
  }
  reverse(all(r));

  pair<int, string> ans = {1e9, "pls no"};
  for (int i = 1; i <= (int)t.size(); i++) {
    bool ok = 1;
    for (int j = 0; j < (int)t.size(); j++) {
      int k = (int)t.size() + i - j - 1;
      if (k < (int)t.size() && t[j] != t[k])
        ok = 0;
    }
    if (!ok)
      continue;
    v<int2> dp(i + 1, {1e9, -1});
    dp[0] = {0, -1};
    for (int j = 1; j <= i; j++) {
      for (int k = 0; k < 36; k++) {
        if ((int)code[k].size() <= j) {
          bool ok = 1;
          for (int p = 0; p < (int)code[k].size(); p++) {
            if (code[k][p] != t[i - j - p + (int)code[k].size() - 1])
              ok = 0;
          }
          if (ok && dp[j - (int)code[k].size()].f < dp[j].f) {
            dp[j] = {dp[j - (int)code[k].size()].f + 1, k};
          }
        }
      }
    }
    string res;
    if (dp[i].s != -1) {
      int cur = i;
      while (cur != 0) {
        res.push_back(unget(dp[cur].s));
        cur -= code[dp[cur].s].size();
      }
      reverse(all(res));
    }
    dbg(res);
    ans = min(ans, {dp[i].f, res});
  }

  for (int i = 0; i < 36; i++) {
    t = r + unget(i);
    for (int i = 1; i <= (int)t.size(); i++) {
      bool ok = 1;
      for (int j = 0; j < (int)t.size(); j++) {
        int k = (int)t.size() + i - j - 1;
        if (k < (int)t.size() && t[j] != t[k])
          ok = 0;
      }
      if (!ok)
        continue;
      v<int2> dp(i + 1, {1e9, -1});
      dp[0] = {0, -1};
      for (int j = 1; j <= i; j++) {
        for (int k = 0; k < 36; k++) {
          if ((int)code[k].size() <= j) {
            bool ok = 1;
            for (int p = 0; p < (int)code[k].size(); p++) {
              if (code[k][p] != t[i - j - p + (int)code[k].size() - 1])
                ok = 0;
            }
            if (ok && dp[j - (int)code[k].size()].f < dp[j].f) {
              dp[j] = {dp[j - (int)code[k].size()].f + 1, k};
            }
          }
        }
      }
      string res;
      if (dp[i].s != -1) {
        int cur = i;
        while (cur != 0) {
          res.push_back(unget(dp[cur].s));
          cur -= code[dp[cur].s].size();
        }
        reverse(all(res));
      }
      dbg(res);
      ans = min(ans, {dp[i].f + 1, unget(i) + res});
    }
  }

  cout << ans.f << ' ' << ans.s << '\n';
}

int main() {
#ifdef DEV_MODE
  debug_start(INTERACTIVE, "l.txt");
#else
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  int t;
  if (MULTITEST)
    cin >> t;
  else
    t = 1;
  while (t--)
    solve();

#ifdef DEV_MODE
  debug_exit(INTERACTIVE);
#endif
}
#ifdef DEV_MODE
#include "debug.cpp"
#endif

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

FOOTS

output:

3 29D

result:

ok correct

Test #3:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

FOOTS

output:

3 29D

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3700kb

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

OOTNX

output:

2 J0

result:

ok correct

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3632kb

input:

3 FRENCH HENS

output:

1 7

result:

wrong answer not a palindrome