結果
| 問題 | No.3626 Not a Prefix |
| コンテスト | |
| ユーザー |
👑 Nachia
|
| 提出日時 | 2026-08-14 21:51:21 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,769 bytes |
| 記録 | |
| コンパイル時間 | 627 ms |
| コンパイル使用メモリ | 112,868 KB |
| 実行使用メモリ | 71,816 KB |
| 最終ジャッジ日時 | 2026-08-14 21:51:25 |
| 合計ジャッジ時間 | 3,747 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 WA * 33 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }
struct Node {
ll lower = 0;
ll upper = 0;
ll just = 0;
map<ll,ll> nx;
};
void testcase(){
ll N, M; cin >> N >> M; M = N - M;
V<string> S(N); REP(i,N) cin >> S[i];
V<Node> trie(1);
for(auto& s : S){
ll p = 0;
for(char c : s){
if(!trie[p].nx.count(c)){
trie[p].nx[c] = trie.size();
trie.push_back(Node());
}
p = trie[p].nx[c];
}
trie[p].lower += 1;
trie[p].upper += 1;
trie[p].just += 1;
}
ll Z = trie.size();
REP(i,Z) for(auto [u,v] : trie[i].nx) trie[v].upper += trie[i].upper;
for(ll i=Z-1; i>=0; i--) for(auto [u,v] : trie[i].nx) trie[i].lower += trie[v].lower;
string ans;
auto dfs = [&](auto& dfs, ll p) -> bool {
if(p != 0 && trie[p].lower + trie[p].upper - trie[p].just < M) return 1;
if(trie[p].upper >= M) return 0;
for(ll k='a'; k<='z'; k++){
if(trie[p].nx.count(k)){
if(dfs(dfs, trie[p].nx[k])){
ans.push_back(k);
return 1;
}
} else {
ans.push_back(k);
return 1;
}
}
return 0;
};
if(dfs(dfs, 0)){
reverse(ans.begin(), ans.end());
cout << "Yes\n";
cout << ans << "\n";
} else {
cout << "No\n";
}
}
int main(){
cin.tie(0)->sync_with_stdio(0);
testcase();
return 0;
}
Nachia