QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697225 | #7705. Make Your Own Morse Code Palindrome | BackToSquare1 | AC ✓ | 1ms | 3884kb | C++20 | 3.5kb | 2024-11-01 12:08:05 | 2024-11-01 12:08:07 |
Judging History
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 = "", inpt;
getline(cin,inpt);
ll nn = inpt.size();
for(ll i=0;i<nn;i++) {
if(inpt[i] >= 'A' && inpt[i] <= 'Z') s += inpt[i];
else if(inpt[i] >= '0' && inpt[i] <= '9') s += inpt[i];
}
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: 3476kb
input:
FOOT
output:
1 L
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
FOOTS
output:
3 0QI
result:
ok correct
Test #3:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
FOOTS
output:
3 0QI
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
FOOTSTOOL
output:
0
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
OOTNX
output:
2 J0
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
3 FRENCH HENS
output:
6 5RCLXB
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
TWAS THE NIGHT BEFORE XMAS
output:
13 YXFOL46PF4VPT
result:
ok correct
Test #8:
score: 0
Accepted
time: 1ms
memory: 3876kb
input:
1A2B3C4D5E6F7G8H9I10J
output:
18 0695OW3L4535Y62X1E
result:
ok correct
Test #9:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
A PARTRIDGE IN A PEAR TREE
output:
8 QF3FFCXC
result:
ok correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
TEN LORDS ALEAPING
output:
9 BQ4L4R8XA
result:
ok correct
Test #11:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
XABCDQRST1234567890123456789
output:
7 6CZCBQU
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
ASDFGHJKLQWERTYUIOPMNBVCXZ987
output:
23 ZO12FY5ROP8XYLQPRY73LFF
result:
ok correct
Test #13:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
THE QUICK BROWN FOX JUMPS OVER
output:
17 24YXQ2C2JR3RCLY5T
result:
ok correct
Test #14:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
1234567891 IS A PRIME NUMBER 0
output:
18 L37YVUC59123456789
result:
ok correct
Test #15:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
INTRANSIGENCE
output:
0
result:
ok correct
Test #16:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
ANTICKING ANTICKING WRECKING A
output:
5 CRCXP
result:
ok correct
Test #17:
score: 0
Accepted
time: 1ms
memory: 3640kb
input:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
output:
1 E
result:
ok correct
Test #18:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
ISO9001 "IEEEEEEEEEEEEEEEEEEEE
output:
6 90018S
result:
ok correct