답안 #1000314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1000314 2024-06-17T08:32:31 Z AtabayRajabli Type Printer (IOI08_printer) C++17
90 / 100
1000 ms 149328 KB
#include <bits/stdc++.h>

// author : a1abay                                                                                                                            

using namespace std;

#define int ll
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const int inff = (int)1e18 + 7;
const int sz = 25e3 + 5;

int n, k, x = 0;
int t[sz * 26][26], mx[sz * 26], d[sz * 26];
bool w[sz * 26];
vector<array<int, 3>> g[sz * 26];
string s;
set<int> st;

void add(int ind, int cur)
{
    if(ind == s.size()) 
    {
        w[cur] = 1;
        return;
    }
    if(t[cur][s[ind] - 'a']) cur = t[cur][s[ind] - 'a'];
    else cur = t[cur][s[ind] - 'a'] = ++x;
    add(ind + 1, cur);
}

void dfs(int v)
{
    bool lf = 1;
    for(int i = 0; i < 26; i++)
    {
        if(!t[v][i]) continue;
        lf = 0;
        int c = t[v][i];
        d[c] = d[v] + 1;
        dfs(c);
        mx[v] = max(mx[v], mx[c]);
    }
    for(int i = 0; i < 26; i++)
    {
        if(!t[v][i]) continue;
        int c = t[v][i];
        g[v].push_back({mx[c], c, i});
    }
    sort(all(g[v]));
    if(lf) mx[v] = d[v];
}

void calc(int v, char c)
{
    if(st.size() == x) return;
    st.insert(v);
    cout << c << endl;
    if(w[v]) cout << "P" << endl;
    for(auto i : g[v])
    {
        calc(i[1], char(i[2] + 'a'));
    }
    if(st.size() < x)cout << "-" << endl;
}

void solve()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> s;
        add(0, 0);
    }
    dfs(0);
    cout << x * 2 - mx[0] + n << endl;
    for(auto i : g[0])
    {
        calc(i[1], char(i[2] + 'a'));
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0); 
    
    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
}

Compilation message

printer.cpp: In function 'void add(ll, ll)':
printer.cpp:25:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     if(ind == s.size())
      |        ~~~~^~~~~~~~~~~
printer.cpp: In function 'void calc(ll, char)':
printer.cpp:59:18: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   59 |     if(st.size() == x) return;
      |        ~~~~~~~~~~^~~~
printer.cpp:67:18: warning: comparison of integer expressions of different signedness: 'std::set<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   67 |     if(st.size() < x)cout << "-" << endl;
      |        ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 3 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 19032 KB Output is correct
2 Correct 4 ms 19096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 11 ms 20136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 20828 KB Output is correct
2 Correct 23 ms 21416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 26196 KB Output is correct
2 Correct 132 ms 34276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 37200 KB Output is correct
2 Correct 45 ms 22864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 404 ms 66904 KB Output is correct
2 Correct 881 ms 130460 KB Output is correct
3 Correct 489 ms 75348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 56780 KB Output is correct
2 Execution timed out 1018 ms 149328 KB Time limit exceeded
3 Halted 0 ms 0 KB -