QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#650073 | #7705. Make Your Own Morse Code Palindrome | enze114514 | WA | 1ms | 3684kb | C++20 | 3.8kb | 2024-10-18 12:28:02 | 2024-10-18 12:28:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
const ld pi = 3.14159265358979323846;
const ll INF = 1e18;
template<typename T>
T chmax(T a, T b) {
return a > b ? a : b;
}
template<typename T>
T chmin(T a, T b) {
return a > b ? b : a;
}
const int N = (int)1e5 + 1, M = N * 2;
unordered_map<char, string> mp1 = {
{'A', ".-"},
{'B', "-..."},
{'C', "-.-."},
{'D', "-.."},
{'E', "."},
{'F', "..-."},
{'G', "--."},
{'H', "...."},
{'I', ".."},
{'J', ".---"},
{'K', "-.-"},
{'L', ".-.."},
{'M', "--"},
{'N', "-."},
{'O', "---"},
{'P', ".--."},
{'Q', "--.-"},
{'R', ".-."},
{'S', "..."},
{'T', "-"},
{'U', "..-"},
{'V', "...-"},
{'W', ".--"},
{'X', "-..-"},
{'Y', "-.--"},
{'Z', "--.."},
{'0', "-----"},
{'1', ".----"},
{'2', "..---"},
{'3', "...--"},
{'4', "....-"},
{'5', "....."},
{'6', "-...."},
{'7', "--..."},
{'8', "---.."},
{'9', "----."}
};
unordered_map<string, char> mp2 = {
{".-", 'A'},
{"-...", 'B'},
{"-.-.", 'C'},
{"-..", 'D'},
{".", 'E'},
{"..-.", 'F'},
{"--.", 'G'},
{"....", 'H'},
{"..", 'I'},
{".---", 'J'},
{"-.-", 'K'},
{".-..", 'L'},
{"--", 'M'},
{"-.", 'N'},
{"---", 'O'},
{".--.", 'P'},
{"--.-", 'Q'},
{".-.", 'R'},
{"...", 'S'},
{"-", 'T'},
{"..-", 'U'},
{"...-", 'V'},
{".--", 'W'},
{"-..-", 'X'},
{"-.--", 'Y'},
{"--..", 'Z'},
{"-----", '0'},
{".----", '1'},
{"..---", '2'},
{"...--", '3'},
{"....-", '4'},
{".....", '5'},
{"-....", '6'},
{"--...", '7'},
{"---..", '8'},
{"----.", '9'}
};
vector<char> ch;
struct Dp{
int v = 0;
vector<char> c;
};
int pld(string t){
int uwu = 0;
for(int l = 0, r = t.size() - 1; l < r; l++, r--){
if(t[l] != t[r]){
uwu = 1;
}
}
return !uwu;
}
vector<char> dp(string s){
int n = s.size();
vector<Dp> f(n + 1);
for(int i = 1; i <= n; i++){
f[i].v = (int)1e9;
}
for(int i = 0; i < n; i++){
for(int j = 0; j < i; j++){
string t = s.substr(j + 1, i - j);
if(mp2.count(t) && f[j].v + 1 < f[i].v){
f[i].v = f[j].v + 1;
f[i].c = f[j].c;
f[i].c.pb(mp2[t]);
}
}
}
return f[n - 1].c;
}
void solve(){
string input, s;
getline(cin, input);
for(char c : input){
if(isalnum(c)){
s += c;
}
}
string ds = "";
for(auto &c : s){
c = toupper(c);
ds += mp1[c];
ch.pb(c);
}
if(pld(ds)){
cout << 0 << endl;
return;
}
for(int i = ds.size() - 1; i >= 0; i--){
string t = ds.substr(i);
if(pld(t)){
string qwq = ds.substr(0, i);
reverse(qwq.begin(), qwq.end());
vector<char> uwu = dp(qwq);
if(uwu.size() < ch.size()){
ch = uwu;
}
}
}
cout << ch.size() << " ";
for(auto v : ch){
cout << v;
} cout << endl;
}
//......-.-.-..-..-..--...
//......-.-.-..-..-..--...
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3656kb
input:
FOOT
output:
1 L
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
FOOTS
output:
3 W0L
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
FOOTS
output:
3 W0L
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
FOOTSTOOL
output:
0
result:
ok correct
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
OOTNX
output:
2 O0
result:
wrong answer not a palindrome