Submission #239574

# Submission time Handle Problem Language Result Execution time Memory
239574 2020-06-16T13:00:40 Z Autoratch Type Printer (IOI08_printer) C++14
60 / 100
16 ms 8064 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 25001;

int n;
string s[N],ans;
int tree[N][26],mxch[N],mxs[N];
int cur[N],cnt;
vector<string> ls;

void add(string s)
{
    int now = 0;
    for(char c : s) 
    {
        if(s.length()>mxs[now]) mxs[now] = s.length(),mxch[now] = c-'a';
        if(tree[now][c-'a']) now = tree[now][c-'a'];
        else tree[now][c-'a'] = ++cnt,now = cnt;
    }
    cur[now]++;
}

void solve(int now,string cu)
{
    while(cur[now]--) ls.push_back(cu);
    for(int i = 0;i < 26;i++) if(tree[now][i])
    {
        if(mxs[now] and mxch[now]==i) continue;
        solve(tree[now][i],cu+(char)(i+'a'));
    }
    if(mxs[now]) solve(tree[now][mxch[now]],cu+(char)(mxch[now]+'a'));
}

void ch(string a,string b)
{
    int sm = 0;
    for(int i = 0,j = 0;i < a.length() and j < b.length() and a[i]==b[j];i++,j++) sm++;
    for(int i = 0;i < a.length()-sm;i++) ans+='-';
    for(int i = sm;i < b.length();i++) ans+=b[i];
    ans+='P';
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);

    cin >> n;
    for(int i = 1;i <= n;i++) cin >> s[i],add(s[i]);
    solve(0,"");
    for(int i = 0;i < ls.size();i++)
    {
        string a = "",b = ls[i];
        if(i) a = ls[i-1];
        ch(a,b);
    }
    cout << ans.length() << '\n';
    for(char c : ans) cout << c << '\n';
}

Compilation message

printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:17:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(s.length()>mxs[now]) mxs[now] = s.length(),mxch[now] = c-'a';
            ~~~~~~~~~~^~~~~~~~~
printer.cpp: In function 'void ch(std::__cxx11::string, std::__cxx11::string)':
printer.cpp:38:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0,j = 0;i < a.length() and j < b.length() and a[i]==b[j];i++,j++) sm++;
                         ~~^~~~~~~~~~~~
printer.cpp:38:46: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0,j = 0;i < a.length() and j < b.length() and a[i]==b[j];i++,j++) sm++;
                                            ~~^~~~~~~~~~~~
printer.cpp:39:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < a.length()-sm;i++) ans+='-';
                   ~~^~~~~~~~~~~~~~~
printer.cpp:40:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = sm;i < b.length();i++) ans+=b[i];
                    ~~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:51:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0;i < ls.size();i++)
                   ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 5 ms 1152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Correct 6 ms 1180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 7 ms 1664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 2176 KB Output is correct
2 Correct 9 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 4480 KB Output is correct
2 Runtime error 15 ms 7936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 7936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 7936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 8064 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -