QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#876459 | #7705. Make Your Own Morse Code Palindrome | WeaRD276 | AC ✓ | 1ms | 3840kb | C++20 | 3.8kb | 2025-01-30 21:29:54 | 2025-01-30 21:29:55 |
Judging History
answer
//A tree without skin will surely die.
//A man without face is invincible.
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, st_, n) for(int i = st_; i < n; ++i)
#define RFOR(i, n, end_) for(int i = (n)-1; i >= end_; --i)
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif
std::map<char, std::string> MC = {
{'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<pair<char, std::string>> MCVec;
std::map<string, char> MCC;
bool f(const string& need, int p, string& res)
{
if(p==sz(need))
{
return true;
}
for(auto [ch, ms]: MCVec)
{
if(p+sz(ms) <= sz(need) && need.substr(p, sz(ms)) == ms)
{
res.pb(ch);
if(f(need,p+sz(ms), res))
{
return true;
}
res.pop_back();
}
}
return false;
}
int solve()
{
string s;
if(!(getline(cin, s)))return 1;
string ss;
for (char ch: s)
{
if (isalpha(ch))
ss += toupper(ch);
else if (isdigit(ch))
ss += ch;
}
s = ss;
MCC=std::map<string, char>{};
for(auto [k, val]: MC) MCC[val]=k;
MCVec=vector<pair<char, std::string>>(all(MC));
sort(all(MCVec), [](const pair<char, std::string>& e1, const pair<char, std::string>& e2) -> bool{
return sz(e1.y) > sz(e2.y);
});
string ms;
for(auto item: s) ms += MC[item];
// ----..-.-..-- [.] -...-.
// ..-.-- -----
string rv = ms;
reverse(all(rv));
if (ms == rv)
{
cout << "0\n";
return 0;
}
string res=string(10000, '?');
//cout<<ms<<'\n';
FOR(i,sz(ms)/2,sz(ms)+1)
{
bool ok=true;
int j,k;
for(j=i,k=i; j < sz(ms); ++j, --k)
{
if(ms[j] != ms[k]) ok=false;
}
if(ok)
{
string t=ms.substr(0,k+1);
//cout<<t<<'\n';
reverse(all(t));
string cur_res;
if(f(t,0, cur_res))
{
if(sz(cur_res) < sz(res))
res=cur_res;
}
}
}
FOR(i,sz(ms)/2,sz(ms)+1)
{
bool ok=true;
int j,k;
for(j=i+1,k=i; j < sz(ms); ++j, --k)
{
if(ms[j] != ms[k]) ok=false;
}
if(ok)
{
string t=ms.substr(0,k+1);
reverse(all(t));
string cur_res;
if(f(t,0, cur_res))
{
if(sz(cur_res) < sz(res))
res=cur_res;
}
}
}
cout<<sz(res)<<" "<<res<<'\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
{
break;
}
#ifdef ONPC
cout << "__________________________" << endl;
#endif
}
#ifdef ONPC
cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
FOOT
output:
1 L
result:
ok correct
Test #2:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
FOOTS
output:
3 0QI
result:
ok correct
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
FOOTS
output:
3 0QI
result:
ok correct
Test #4:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
FOOTSTOOL
output:
0
result:
ok correct
Test #5:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
OOTNX
output:
3 F0O
result:
ok correct
Test #6:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3 FRENCH HENS
output:
6 5RCLXB
result:
ok correct
Test #7:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
TWAS THE NIGHT BEFORE XMAS
output:
13 YXFOL46PF4VPT
result:
ok correct
Test #8:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
1A2B3C4D5E6F7G8H9I10J
output:
18 0695OPUC5646R848YG
result:
ok correct
Test #9:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
A PARTRIDGE IN A PEAR TREE
output:
8 QF3FFCXC
result:
ok correct
Test #10:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
TEN LORDS ALEAPING
output:
9 BQ4L4R8XA
result:
ok correct
Test #11:
score: 0
Accepted
time: 1ms
memory: 3840kb
input:
XABCDQRST1234567890123456789
output:
7 6CZCBQU
result:
ok correct
Test #12:
score: 0
Accepted
time: 0ms
memory: 3712kb
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 24YXQ2C2JLUCCLY5T
result:
ok correct
Test #14:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
1234567891 IS A PRIME NUMBER 0
output:
18 L37YVUC59123456789
result:
ok correct
Test #15:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
INTRANSIGENCE
output:
0
result:
ok correct
Test #16:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
ANTICKING ANTICKING WRECKING A
output:
5 CRCXP
result:
ok correct
Test #17:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
output:
1 E
result:
ok correct
Test #18:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
ISO9001 "IEEEEEEEEEEEEEEEEEEEE
output:
6 110Y05
result:
ok correct