QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#650072#7705. Make Your Own Morse Code Palindromeenze114514WA 1ms3652kbC++203.9kb2024-10-18 12:27:332024-10-18 12:27:34

Judging History

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

  • [2024-10-18 12:27:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2024-10-18 12:27:33]
  • 提交

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());
            cout << qwq << endl;
            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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3652kb

input:

FOOT

output:

------.-..
-----.-..
----.-..
---.-..
--.-..
-.-..
.-..
1 L

result:

wrong output format Expected integer, but "------.-.." found