답안 #534025

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534025 2022-03-07T20:37:50 Z __Variatto Type Printer (IOI08_printer) C++17
100 / 100
177 ms 115288 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define ll long long
const int A=30;
const int MAX=25e3+10;
struct st{
    st* a[A];
    int kon;
};
int n;
string s[MAX];
void stworz(st *v, char c){
    if(v->a[c-'a']!=nullptr)
        return;
    st *nowy=new st;
    for(int i=0; i<A; i++)
        nowy->a[i]=nullptr;
    nowy->kon=0;
    v->a[c-'a']=nowy;
}
void dodaj(st* r, string s){
    st *x=r;
    for(int i=0; i<s.size(); i++){
        stworz(x, s[i]);
        x=x->a[s[i]-'a'];
    }
    x->kon++;
}
string ost;
vector<char>wyn;
void dfs(st* v, int j){
    for(int i=1; i<=v->kon; i++)
        wyn.pb('P');
    for(int i=0; i<A; i++){
        if(i==ost[j]-'a')
            continue;
        if(v->a[i]!=nullptr){
            wyn.pb(char(i+'a'));
            dfs(v->a[i], j+1);
        }
    }
    //return;
    if(j<ost.size() && v->a[ost[j]-'a']!=nullptr){
        wyn.pb(ost[j]);
        dfs(v->a[ost[j]-'a'], j+1);
    }
    wyn.pb('-');
}
int main(){
/*    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
*/    cin>>n;
    st *r=new st;
    for(int i=0; i<A; i++)
        r->a[i]=nullptr;
    r->kon=0;
    pair<int,int> maxi={0,0};
    for(int i=1; i<=n; i++){
        cin>>s[i];
        dodaj(r, s[i]);
        maxi=max(maxi, {int(s[i].size()), i});
    }
    ost=s[maxi.se];
    dfs(r, 0);
    while(wyn.size() && wyn.back()=='-')
        wyn.pop_back();
    cout<<wyn.size()<<"\n";
    for(auto x: wyn)
        cout<<x<<"\n";
}

Compilation message

printer.cpp: In function 'void dodaj(st*, std::string)':
printer.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0; i<s.size(); i++){
      |                  ~^~~~~~~~~
printer.cpp: In function 'void dfs(st*, int)':
printer.cpp:46:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     if(j<ost.size() && v->a[ost[j]-'a']!=nullptr){
      |        ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1076 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1080 KB Output is correct
2 Correct 1 ms 1100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 1080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1100 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 2 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2704 KB Output is correct
2 Correct 5 ms 3264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 7468 KB Output is correct
2 Correct 23 ms 15044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 17460 KB Output is correct
2 Correct 11 ms 4672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 42684 KB Output is correct
2 Correct 142 ms 96948 KB Output is correct
3 Correct 86 ms 50836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 33232 KB Output is correct
2 Correct 177 ms 115288 KB Output is correct
3 Correct 104 ms 57656 KB Output is correct
4 Correct 174 ms 108824 KB Output is correct