답안 #444015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
444015 2021-07-13T01:33:35 Z cpp219 Type Printer (IOI08_printer) C++14
70 / 100
202 ms 99560 KB
#pragma GCC optimization O2
#pragma GCC optimization "unroll-loop"
#pragma target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e5 + 9;
const ll Log2 = 20;
const ll inf = 1e9 + 7;

deque<char> ans;
string s;
ll n;

struct Trie{
    Trie *child[26]; ll End,mx;
    Trie (){
        for (ll i = 0;i < 26;i++) child[i] = NULL;
        End = 0; mx = 0;
    }
    void Add(ll pos,string &s){
        if (pos == s.size()){
            End++; mx = 1; return;
        }
        ll now = s[pos] - 'a';
        if (!child[now]) child[now] = new Trie;
        child[now] -> Add(pos + 1,s);
        mx = max(mx,child[now] -> mx + 1);
    }
    void DFS(){
        while(End--) ans.push_back('P');
        ll cur = 0,chosen = 0;
        for (ll i = 0;i < 26;i++) if (child[i] && cur < child[i] -> mx)
            cur = child[i] -> mx, chosen = i;
        for (ll i = 0;i < 26;i++){
            if (child[i] && i != chosen) ans.push_back(i + 'a'),child[i] -> DFS();
        }
        if (child[chosen]) ans.push_back(chosen + 'a'),child[chosen] -> DFS();
        ans.push_back('-');
    }
};

Trie Tree;

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "tst"
    if (fopen(task".INP","r")){
        freopen(task".INP","r",stdin);
        //freopen(task".OUT","w",stdout);
    }
    cin>>n;
    for (ll i = 1;i <= n;i++){
        cin>>s; Tree.Add(0,s);
    }
    Tree.DFS();
    while(ans.back() == '-') ans.pop_back();
    cout<<ans.size()<<"\n";
    for (auto i : ans) cout<<i<<"\n";
}

Compilation message

printer.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
printer.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
printer.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
printer.cpp: In member function 'void Trie::Add(int, std::string&)':
printer.cpp:27:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         if (pos == s.size()){
      |             ~~~~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1740 KB Output is correct
2 Incorrect 5 ms 2252 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5836 KB Output is correct
2 Correct 27 ms 12336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 14640 KB Output is correct
2 Correct 10 ms 3276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 36432 KB Output is correct
2 Correct 167 ms 83652 KB Output is correct
3 Correct 90 ms 43048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 28484 KB Output is correct
2 Correct 202 ms 99560 KB Output is correct
3 Correct 103 ms 48836 KB Output is correct
4 Correct 180 ms 93944 KB Output is correct