답안 #839663

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
839663 2023-08-30T11:41:12 Z ZeroCool Type Printer (IOI08_printer) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define mp make_pair

using ll = long long;
using ld = long double;


 
void solve(int T);
void pre();
 
const int mxn = 405;
const int mxm = 405;
const int SQRT = 500;
const int LOG = 20;
const int inf = 1e18;
const int mod = 1e9 + 7;
const ld eps = 1e-9;
 
void pre(){
	#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
	#endif
	
}




int32_t main(){
	pre();
	int tt = 1;
	//cin>>tt;
	for(int i = 1;i<=tt;i++){
		#ifndef ONLINE_JUDGE
		cout<<"Case "<<i<<": "<<endl;
		#endif
		solve(i);
	}
    return 0;
}



struct Node{
    bool word;
    int chars;
    map<char, Node*> child;

    Node(){
        word = false;
        chars = 0;
    }

    ~Node(){
        for(auto p : child){
            delete p.second;
        }
    }
};

bool cmp(pair<Node*, char> a, pair<Node*, char> b) {
    return (a.first->chars) < (b.first->chars);
}
struct Trie{


    Node *root;

    int totalW;
    int totalO;
    int totalF;
    string ans;

    Trie(){
        root= new Node();
        totalW = 0;
        ans = "";
        totalO = 0;
    }

    ~Trie(){
        delete root;
    }

    void insert(string word){
        Node *curr = root;
        int add = 0;

        for(char &ch : word){
            if(!curr->child.count(ch)){
                curr->child[ch] = new Node();
            }

            curr = curr->child[ch];
            curr->chars = max(curr->chars, word.size() - add);
            add++;
        }

        curr->word = true;

        totalW++;
    }

    void dfs(Node *curr, char ch){
        if(ch != ' '){
            ans += ch;
            totalO++;
        }

        if(curr->word){
            ans += 'P';
            totalO++;
            totalF++;
        }

        vector<pair<Node*, char> > nex;

        for(auto n : curr->child){
            nex.pb({n.second, n.first});
        }

        sort(nex.begin(), nex.end(), cmp);

        for(auto n : nex){
            dfs(n.first, n.second);
        }

        if(ch != ' ' && totalF < totalW){
            ans+='-';
            totalO++;
        }
    }

    void dfs(){
        totalF = 0;

        dfs(root, ' ');
        cout<<totalO<<endl;

        for(char c : ans)cout<<c<<endl;
    }
};

void solve(int T){
	int n;
    cin>>n;
    Trie t;

    for(int i = 0;i<n;i++){
        string s;
        cin>>s;
        t.insert(s);
    }

    t.dfs();
}

Compilation message

printer.cpp: In member function 'void Trie::insert(std::string)':
printer.cpp:101:61: error: no matching function for call to 'max(long long int&, long long unsigned int)'
  101 |             curr->chars = max(curr->chars, word.size() - add);
      |                                                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
printer.cpp:101:61: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  101 |             curr->chars = max(curr->chars, word.size() - add);
      |                                                             ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
printer.cpp:101:61: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  101 |             curr->chars = max(curr->chars, word.size() - add);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3480:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3480 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3480:5: note:   template argument deduction/substitution failed:
printer.cpp:101:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  101 |             curr->chars = max(curr->chars, word.size() - add);
      |                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from printer.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3486:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3486 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3486:5: note:   template argument deduction/substitution failed:
printer.cpp:101:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  101 |             curr->chars = max(curr->chars, word.size() - add);
      |                                                             ^