QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697216#7705. Make Your Own Morse Code PalindromeBackToSquare1WA 0ms3844kbC++203.3kb2024-11-01 11:59:112024-11-01 11:59:12

Judging History

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

  • [2024-11-01 11:59:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-11-01 11:59:11]
  • 提交

answer

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
 
typedef pair<ll, ll> pl;
typedef pair<ld,ld> pd;
typedef vector<ll> vl;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
 
#define G(x) ll x; cin >> x;
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define all(a) begin(a), end(a)
#define K first
#define V second
#define OK(i,j) i >= 0 && i < n && j >= 0 && j < m
 
#define NN 2000005
#define MM 5005
#define MOD 1000000007

map<char,string> m;
map<string,char> mm;
set<string> valid;
ll dp[150];
ll val[150];

bool isPalindrome(string s) {
    string t = s;
    reverse(t.begin(),t.end());
    return s == t;
}

void solve() {

    string s;
    cin >> s;
    ll n = s.length();
    string t = "";
    for(ll i=0;i<n;i++) {
        t += m[s[i]];
    }

    if(isPalindrome(t)) {
        cout << 0 << '\n';
        return;
    }

    ll ans = 1e4;
    string answer = "";
    ll k = t.length();
    for(ll i=1;i<=k;i++) {
        string u = t.substr(0,i);
        reverse(u.begin(),u.end());
        u = t + u;
        if(!isPalindrome(u)) continue;
        // cout << u << '\n';

        u = t.substr(0,i);
        reverse(u.begin(),u.end());

        for(ll j=0;j<i;j++) dp[j] = 1e9;

        for(ll j=0;j<i;j++) {
            for(ll k=1;k<=5;k++) {
                if(j-k+1 < 0) continue;
                string v = u.substr(j-k+1,k);
                if(valid.count(v) > 0) {
                    if(j-k+1 == 0) {
                        dp[j] = 1;
                        val[j] = k;
                    }
                    else if(dp[j-k] + 1 < dp[j]) {
                        dp[j] = dp[j-k] + 1;
                        val[j] = k;
                    }
                }
            }
        }

        if(dp[i-1] < ans) {
            ans = dp[i-1];
            answer = "";
            ll j = i-1;
            while(j >= 0) {
                string v = u.substr(j-val[j]+1,val[j]);
                answer += mm[v];
                j -= val[j];
            }
        }
    }

    reverse(answer.begin(),answer.end());

    cout << ans << ' ' << answer << '\n';

}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cout << fixed << setprecision(10);

    m['A'] = ".-";
    m['B'] = "-...";
    m['C'] = "-.-.";
    m['D'] = "-..";
    m['E'] = ".";
    m['F'] = "..-.";
    m['G'] = "--.";
    m['H'] = "....";
    m['I'] = "..";
    m['J'] = ".---";
    m['K'] = "-.-";
    m['L'] = ".-..";
    m['M'] = "--";
    m['N'] = "-.";
    m['O'] = "---";
    m['P'] = ".--.";
    m['Q'] = "--.-";
    m['R'] = ".-.";
    m['S'] = "...";
    m['T'] = "-";
    m['U'] = "..-";
    m['V'] = "...-";
    m['W'] = ".--";
    m['X'] = "-..-";
    m['Y'] = "-.--";
    m['Z'] = "--..";
    m['0'] = "-----";
    m['1'] = ".----";
    m['2'] = "..---";
    m['3'] = "...--";
    m['4'] = "....-";
    m['5'] = ".....";
    m['6'] = "-....";
    m['7'] = "--...";
    m['8'] = "---..";
    m['9'] = "----.";

    for(auto x : m) {
        mm[x.V] = x.K;
        valid.insert(x.V);
    }

    // G(t);
    // while(t--)
        solve();

    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

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

input:

FOOTS

output:

3 0QI

result:

ok correct

Test #3:

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

input:

FOOTS

output:

3 0QI

result:

ok correct

Test #4:

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

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

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

input:

OOTNX

output:

2 J0

result:

ok correct

Test #6:

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

input:

3 FRENCH HENS

output:

1 S

result:

wrong answer not a palindrome