Submission #1094529

# Submission time Handle Problem Language Result Execution time Memory
1094529 2024-09-29T19:35:40 Z vjudge1 Type Printer (IOI08_printer) C++17
20 / 100
52 ms 38864 KB
//    #pragma GCC optimize ("O3")
//    #pragma GCC optimize ("unroll-loops")
//    #pragma comment(linker, "/STACK:2000000")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define ld long double
#define endl "\n"
#define FOCUS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void Go() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
ll node=1;
struct trienode
{
    trienode* child[26];
    bool wordEnd;
    ll cur_node;
    ll mx;

    trienode()
    {
        wordEnd=false;
        for(auto &it:child)it= nullptr;
        cur_node=0;
    }

};
struct Trie
{

    trienode* root=new trienode();
    void insert(string s)
    {
        trienode* cur=root;
        ll cnt=0;
        for(auto it:s)
        {
            if(cur->child[it-'a']== nullptr)
                cur->child[it-'a']=new trienode (),cur->child[it-'a']->cur_node=node++;
            cur=cur->child[it-'a'];
            cur->mx=max(cur->mx,(int)s.size()-cnt++);


        }

        cur->wordEnd=true;
    }
    bool search(string s)
    {
        trienode*cur=root;
        for(auto it:s)
        {
            if(cur->child[it-'a']== nullptr)return false;
            cur=cur->child[it-'a'];
        }
        return cur->wordEnd;
    }
};
int depth[25001];
vector<char>ans;
void dfs(trienode* cur)
{
    vector<pair<ll,ll>>temp;
    for(int i=0;i<=25;i++)
    {
        if(cur->child[i]!= nullptr)
            temp.push_back({cur->child[i]->mx,i});

    }
    sort(temp.begin(),temp.end());
    for(auto it:temp)
    {
        ans.push_back((char)(it.second+'a'));
        dfs(cur->child[it.second]);
        if(cur->child[it.second]->wordEnd)
            ans.push_back('P');
        ans.push_back('-');
    }

}
signed main() {
    //Go();
    ll n;
    cin>>n;
    Trie trie;
    for(int i=0;i<n;i++)
    {
        string x;
        cin>>x;
        trie.insert(x);
    }
    dfs(trie.root);
    while (ans.size()&&ans.back()=='-')ans.pop_back();
    cout<<ans.size()<<endl;
    for(auto it:ans)
        cout<<it<<endl;
    return 0;
}

Compilation message

printer.cpp: In function 'void Go()':
printer.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 6488 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 15832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 38864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 30412 KB Output isn't correct
2 Halted 0 ms 0 KB -