답안 #819014

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
819014 2023-08-10T07:38:28 Z Sir_Ahmed_Imran Type Printer (IOI08_printer) C++17
100 / 100
110 ms 98548 KB
               ///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ld long double
#define append push_back
#define add insert
#define nl "\n"
#define ff first
#define ss second
#define pii pair<int,int>
#define pic pair<int,char>
#define all(x) (x).begin(),(x).end()
#define sum(a) accumulate(all(a),0)
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL)
#define terminator main
#define MAXN 100001
class TrieNode {
public:
    int z;
    bool prt;
    TrieNode* nxt[26];
    TrieNode(){
        for(int i=prt=z=0;i<26;i++)
            nxt[i]=NULL;
    }
};
class Trie{
public:
    TrieNode* root;
    int siz;
    Trie(){
        siz=0;
        root=new TrieNode();
    }
    void insert(string a){
        int m;
        TrieNode* x=root;
        for(int i=0;i<a.size();i++){
            m=a[i]-'a';
            if(!x->nxt[m]){
                siz++;
                x->nxt[m]=new TrieNode();
            }
            x=x->nxt[m];
            if(a.size()>x->z)
                x->z=a.size(); 
        }
        x->prt=1;
    }
    void dfs(TrieNode* x){
        vector<pii> v;
        for(int i=0;i<26;i++)
            if(x->nxt[i])
                v.append({x->nxt[i]->z,i});
        sort(all(v));
        for(auto& i:v){
            siz--;
            cout<<char(i.ss+'a')<<nl;
            if(x->nxt[i.ss]->prt){
                siz--;
                cout<<'P'<<nl;
            }
            dfs(x->nxt[i.ss]);
            if(siz>0) cout<<'-'<<nl;
            siz--;
        }
    }
};
void solve(){
    string a;
    int n,m,o,p,q;
    Trie x;
    cin>>n;
    for(int i=m=0;i<n;i++){
        cin>>a;
        x.insert(a);
        if(a.size()>m)
            m=a.size();
    }
    x.siz=x.siz*2+n-m;
    cout<<x.siz<<nl;
    x.dfs(x.root);
}
int terminator(){
    L0TA;
    solve();
    return 0;
}

Compilation message

printer.cpp: In constructor 'TrieNode::TrieNode()':
printer.cpp:25:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   25 |         for(int i=prt=z=0;i<26;i++)
      |                       ~^~
printer.cpp: In member function 'void Trie::insert(std::string)':
printer.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
printer.cpp:47:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |             if(a.size()>x->z)
      |                ~~~~~~~~^~~~~
printer.cpp: In function 'void solve()':
printer.cpp:79:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |         if(a.size()>m)
      |            ~~~~~~~~^~
printer.cpp:73:13: warning: unused variable 'o' [-Wunused-variable]
   73 |     int n,m,o,p,q;
      |             ^
printer.cpp:73:15: warning: unused variable 'p' [-Wunused-variable]
   73 |     int n,m,o,p,q;
      |               ^
printer.cpp:73:17: warning: unused variable 'q' [-Wunused-variable]
   73 |     int n,m,o,p,q;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1740 KB Output is correct
2 Correct 4 ms 2120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5844 KB Output is correct
2 Correct 16 ms 12240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 14528 KB Output is correct
2 Correct 6 ms 3284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 36148 KB Output is correct
2 Correct 92 ms 82896 KB Output is correct
3 Correct 50 ms 42588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 28236 KB Output is correct
2 Correct 110 ms 98548 KB Output is correct
3 Correct 58 ms 48432 KB Output is correct
4 Correct 98 ms 93044 KB Output is correct