QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#650103#7705. Make Your Own Morse Code Palindromeenze114514AC ✓1ms3848kbC++204.0kb2024-10-18 12:56:572024-10-18 12:56:57

Judging History

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

  • [2024-10-18 12:56:57]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3848kb
  • [2024-10-18 12:56:57]
  • 提交

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);

    s = "#" + s;

    for(int i = 1; i <= n; i++){
        f[i].v = (int)1e9;
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            string t = s.substr(j, i - j + 1);
            if(mp2.count(t) && (j == 0 || f[j - 1].v + 1 < f[i].v)){
                if(j == 0){
                    f[i].v = 1;
                }
                else{
                    f[i].v = f[j - 1].v + 1;
                    f[i].c = f[j - 1].c;
                }
                f[i].c.pb(mp2[t]);
            }
        }
    }
    return f[n].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;
    }
    // cout << ds << endl;
    for(int i = ds.size() - 1; i >= 1; i--){
        string t = ds.substr(i);
        // cout << "here " << t << endl;
        if(pld(t)){
            string qwq = ds.substr(0, i);
            reverse(qwq.begin(), qwq.end());
            vector<char> uwu = dp(qwq);
            // cout << qwq << " " << uwu.size() << endl;
            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: 3600kb

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

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

input:

FOOTS

output:

3 29D

result:

ok correct

Test #3:

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

input:

FOOTS

output:

3 29D

result:

ok correct

Test #4:

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

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

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

input:

OOTNX

output:

2 J0

result:

ok correct

Test #6:

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

input:

3 FRENCH HENS

output:

6 HFKFL7

result:

ok correct

Test #7:

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

input:

TWAS THE NIGHT BEFORE XMAS

output:

13 F8DKGB357BFFQ

result:

ok correct

Test #8:

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

input:

1A2B3C4D5E6F7G8H9I10J

output:

18 10484G7Q5L5P4J51F9

result:

ok correct

Test #9:

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

input:

A PARTRIDGE IN A PEAR TREE

output:

8 QF3FFCXC

result:

ok correct

Test #10:

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

input:

TEN LORDS ALEAPING

output:

9 DP6C5C8DK

result:

ok correct

Test #11:

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

input:

XABCDQRST1234567890123456789

output:

7 6CZKLPX

result:

ok correct

Test #12:

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

input:

ASDFGHJKLQWERTYUIOPMNBVCXZ987

output:

23 UXQ88CZ4JP8DQCPYFY73LFF

result:

ok correct

Test #13:

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

input:

THE QUICK BROWN FOX JUMPS OVER

output:

17 24YXQ2KVQGBPKLXP4

result:

ok correct

Test #14:

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

input:

1234567891 IS A PRIME NUMBER 0

output:

18 Q59F7XC59123456789

result:

ok correct

Test #15:

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

input:

INTRANSIGENCE

output:

0

result:

ok correct

Test #16:

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

input:

ANTICKING ANTICKING WRECKING A

output:

5 KFCXP

result:

ok correct

Test #17:

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

input:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

output:

1 R

result:

ok correct

Test #18:

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

input:

ISO9001 "IEEEEEEEEEEEEEEEEEEEE

output:

6 110Y05

result:

ok correct