Submission #811002

# Submission time Handle Problem Language Result Execution time Memory
811002 2023-08-06T19:37:58 Z sofija6 Type Printer (IOI08_printer) C++14
20 / 100
35 ms 29840 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];
void Add(ll cur,ll pos)
{
    if (pos==s.size())
        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 (G[cur].empty())
        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:32: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]
   32 |     if (pos==maxx.size())
      |         ~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Correct 10 ms 23696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 23696 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 23764 KB Output is correct
2 Incorrect 10 ms 23816 KB didn't print every word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 23764 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 24020 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 24788 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 26304 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 29840 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 28396 KB didn't print every word
2 Halted 0 ms 0 KB -