Submission #811003

# Submission time Handle Problem Language Result Execution time Memory
811003 2023-08-06T19:41:38 Z sofija6 Type Printer (IOI08_printer) C++14
100 / 100
93 ms 41020 KB
#include <bits/stdc++.h>
#define ll long long
#define MAXC 1000010
using namespace std;
vector<ll> G[MAXC];
vector<char> ans;
char val[MAXC];
string s,maxx;
ll ind=2;
bool lastt[MAXC],endd[MAXC];
void Add(ll cur,ll pos)
{
    if (pos==s.size())
    {
        endd[cur]=true;
        return;
    }
    ll x=-1;
    for (ll next : G[cur])
    {
        if (val[next]==s[pos])
            x=next;
    }
    if (x==-1)
    {
        x=ind++;
        val[x]=s[pos];
        G[cur].push_back(x);
    }
    Add(x,pos+1);
}
void Find(ll cur,ll pos)
{
    lastt[cur]=true;
    if (pos==maxx.size())
        return;
    ll x=-1;
    for (ll next : G[cur])
    {
        if (val[next]==maxx[pos])
            x=next;
    }
    Find(x,pos+1);
}
void Solve(ll cur)
{
    if (endd[cur])
        ans.push_back('P');
    for (ll next : G[cur])
    {
        if (!lastt[next])
        {
            ans.push_back(val[next]);
            Solve(next);
        }
    }
    for (ll next : G[cur])
    {
        if (lastt[next])
        {
            ans.push_back(val[next]);
            Solve(next);
        }
    }
    if (!lastt[cur])
        ans.push_back('-');
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    for (ll i=1;i<=n;i++)
    {
        cin >> s;
        Add(1,0);
        if (s.size()>maxx.size())
            maxx=s;
    }
    Find(1,0);
    Solve(1);
    cout << ans.size() << "\n";
    for (char i : ans)
        cout << i << "\n";
    return 0;
}

Compilation message

printer.cpp: In function 'void Add(long long int, long long int)':
printer.cpp:13:12: 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]
   13 |     if (pos==s.size())
      |         ~~~^~~~~~~~~~
printer.cpp: In function 'void Find(long long int, long long int)':
printer.cpp:35:12: 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]
   35 |     if (pos==maxx.size())
      |         ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23764 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23844 KB Output is correct
2 Correct 11 ms 23952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23968 KB Output is correct
2 Correct 12 ms 24188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 24728 KB Output is correct
2 Correct 19 ms 26004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 26220 KB Output is correct
2 Correct 15 ms 24532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 29844 KB Output is correct
2 Correct 67 ms 38216 KB Output is correct
3 Correct 40 ms 31296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 28384 KB Output is correct
2 Correct 93 ms 41020 KB Output is correct
3 Correct 44 ms 32256 KB Output is correct
4 Correct 63 ms 40136 KB Output is correct