QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#723910 | #7705. Make Your Own Morse Code Palindrome | MattTheNub# | WA | 1ms | 3672kb | C++23 | 3.8kb | 2024-11-08 03:28:01 | 2024-11-08 03:28:01 |
Judging History
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;
}
dbg(t.size(), t);
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});
}
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: 3620kb
input:
FOOT
output:
1 L
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
FOOTS
output:
3 29D
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
FOOTS
output:
3 29D
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
FOOTSTOOL
output:
0
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
OOTNX
output:
2 J0
result:
ok correct
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3672kb
input:
3 FRENCH HENS
output:
1 7
result:
wrong answer not a palindrome