Submission #428286

# Submission time Handle Problem Language Result Execution time Memory
428286 2021-06-15T09:39:33 Z Atlant Type Printer (IOI08_printer) C++14
20 / 100
39 ms 15904 KB
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool minn(T &A,T B){return A > B ? (A = B,1) : 0;}
template <class T> inline bool maxx(T &A,T B){return A < B ? (A = B,1) : 0;}
#define pb push_back
#define endl '\n'
#define SZ(x) (int)((x).size())
#define dem(x) __builtin_popcount(x)
#define fi first
#define se second
//#define int long long
typedef pair<int,int> ii;
typedef long long ll;
const ll mod = 1e9 + 7; //998244353
vector<int> a[400005];
char c[400005], ans[400005];
string s;
int d[400005], n, best[400005], cnt, t;
void add(int id,string s,int it)
{
    if(it == SZ(s))return;
    bool ck = 1;
    for(int i : a[id])if(c[i] == s[it]){
        ck = 0;
        add(i, s, it + 1);
        if(maxx(d[id], d[i] + 1))best[id] = i;
        break;
    }
    if(ck){
        cnt++;
        a[id].pb(cnt);
        c[cnt] = s[it];
        add(cnt, s, it + 1);
        if(maxx(d[id], d[a[id].back()] + 1))best[id] = a[id].back();
    }
}
void DFS(int id)
{
    ans[++t] = c[id];
    if(SZ(a[id]) == 0){
        cnt++;
        ans[++t] = 'P';
        if(cnt == n){
            cout << t - 1 << endl;
            for(int i = 2;i <= t;++i)cout << ans[i] << endl;
            exit(0);
        }
        ans[++t] = '-';
        return;
    }
    for(int i : a[id])if(i != best[id])DFS(i);
    DFS(best[id]);
    ans[++t] = '-';
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("c.inp","r",stdin);
    cin >> n;
    for(int i = 0;i < n;++i){
        cin >> s;
        add(0, s, 0);
    }
    cnt = 0;
    DFS(0);
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Correct 6 ms 9676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9676 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9676 KB Output is correct
2 Incorrect 7 ms 9676 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 9676 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 9932 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 10692 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 15904 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 14284 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -