# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
921202 | Alihan_8 | Type Printer (IOI08_printer) | C++17 | 112 ms | 112320 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
vector <char> op;
string t;
struct Trie{
struct Info{
int a[26];
Info(int x = -1){
memset(a, x, sizeof(a));
}
};
vector <Info> T;
vector <int> us;
Trie() : T({Info()}), us({0}) {}
void ins(string s){
int rt = 0;
for ( auto &i: s ){
int x = i - 'a';
if ( T[rt].a[x] == -1 ){
T[rt].a[x] = (int)T.size();
T.pb(Info());
us.pb(0);
} rt = T[rt].a[x];
}
us[rt] = true;
}
void dfs(int rt, int d){
if ( us[rt] ){
us[rt] = false;
op.pb('P');
}
if ( d == t.size() ){
return;
}
int x = t[d] - 'a';
for ( int i = 0; i < 26; i++ ){
if ( i != x && T[rt].a[i] != -1 ){
op.pb(i + 'a');
dfs(T[rt].a[i], d + 1);
}
}
if ( T[rt].a[x] != -1 ){
op.pb(x + 'a');
dfs(T[rt].a[x], d + 1);
} op.pb('-');
}
} tr;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector <string> s(n);
for ( auto &x: s ){
cin >> x;
if ( x.size() > t.size() ){
t = x;
} tr.ins(x);
}
tr.dfs(0, 0);
while ( op.back() == '-' ){
op.pop_back();
}
cout << op.size() << ln;
for ( auto &x: op ){
cout << x << ln;
}
// cout << '\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |