답안 #930251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930251 2024-02-19T07:53:13 Z Aiperiii Type Printer (IOI08_printer) C++14
100 / 100
135 ms 95684 KB
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
const int N=1e6;
struct Trie{
    int out=0,last=0;
    map <char,int> mp;
};
Trie t[N];
int cnt=0;
void insert(string s){
    int p=0;
    for(int i=0;i<s.size();i++){
        if(t[p].mp[s[i]]==0){
            cnt++;
            t[p].mp[s[i]]=cnt;
        }
        p=t[p].mp[s[i]];
    }
    t[p].out=1;
}
void mark_last(string s){
    int p=0;
    for(int i=0;i<s.size();i++){
        p=t[p].mp[s[i]];
        t[p].last=1;
    }
}
vector <char> ans;
void get(int p,char c){
    if(p!=0)ans.pb(c);
    if(t[p].out==1)ans.pb('P');
    for(auto i : t[p].mp){
        if(!t[i.ss].last)get(i.ss,i.ff);
    }
    for(auto i : t[p].mp){
        if(t[i.ss].last)get(i.ss,i.ff);
    }
    ans.pb('-');
}

signed main(){
    ios_base::sync_with_stdio();
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <string> s(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    string ls="";
    for(int i=0;i<s.size();i++){
        insert(s[i]);
        if(s[i].size()>ls.size()){
            ls=s[i];
        }
    }
    mark_last(ls);
    get(0,'S');
    while(ans.back()=='-')ans.pop_back();
    cout<<ans.size()<<"\n";
    for(auto x : ans){
        cout<<x<<"\n";
    }
}

/*

 */

Compilation message

printer.cpp: In function 'void insert(std::string)':
printer.cpp:17:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
printer.cpp: In function 'void mark_last(std::string)':
printer.cpp:28:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:56:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 62800 KB Output is correct
2 Correct 16 ms 62808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 63068 KB Output is correct
2 Correct 15 ms 62812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 63064 KB Output is correct
2 Correct 15 ms 62812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 63068 KB Output is correct
2 Correct 14 ms 63068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 63068 KB Output is correct
2 Correct 16 ms 63164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 63320 KB Output is correct
2 Correct 18 ms 63580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 64860 KB Output is correct
2 Correct 29 ms 67156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 67812 KB Output is correct
2 Correct 24 ms 64604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 74932 KB Output is correct
2 Correct 112 ms 90316 KB Output is correct
3 Correct 73 ms 78052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 72332 KB Output is correct
2 Correct 135 ms 95684 KB Output is correct
3 Correct 83 ms 80332 KB Output is correct
4 Correct 103 ms 93868 KB Output is correct