답안 #675807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
675807 2022-12-28T01:56:15 Z Cookie Type Printer (IOI08_printer) C++14
100 / 100
104 ms 49948 KB
#include<bits/stdc++.h>

#include<fstream>

using namespace std;
ifstream fin("inpppp.txt");
ofstream fout("outt.txt");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 25000;

const ll p[4] = {2, 3, 5, 7};
int n, mx = 0, t = 0;
string no;
struct th{
    int nxt[26] = {};
    bool end = false;
};
vt<char>res;
th trie[mxn * 21];
bool spe[mxn * 21];
void add(string s){
    int nd = 0;
    for(int i = 0; i < s.size(); i++){
        int c = s[i] - 'a';
        if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
        nd = trie[nd].nxt[c]; 
    }
    trie[nd].end = true;
}
void find(string s){
    int nd  =0;
    for(int i = 0; i < s.size(); i++){
        int c = s[i] - 'a';
        if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
        nd = trie[nd].nxt[c]; spe[nd] = true;
    }
}
void dfs(int s){
   
    for(int i = 0; i < 26; i++){
        int v = trie[s].nxt[i];
        if(!spe[v] && v){
            
            res.pb((char)(i + 'a'));
            if(trie[v].end)res.pb('P');
            dfs(v);
        }
    }
    for(int i = 0; i < 26; i++){
        int v = trie[s].nxt[i];
        if(spe[v] && v){
           
            res.pb((char)(i + 'a'));
            if(trie[v].end)res.pb('P');
            dfs(v);
        }
    }
    
    if(!spe[s])res.pb('-');
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    spe[0] = true;
    forr(i, 0, n){
        string s; cin >> s; 
        add(s);
        if(s.size() > mx){
            mx = s.size(); no = s;
        }
    }
    find(no);
    dfs(0);
    cout << res.size() << "\n";
    for(auto i: res)cout << i << "\n";
    return 0;
}

Compilation message

printer.cpp: In function 'void add(std::string)':
printer.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'void find(std::string)':
printer.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:79:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |         if(s.size() > mx){
      |            ~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1108 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3080 KB Output is correct
2 Correct 13 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 7512 KB Output is correct
2 Correct 6 ms 2004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 18336 KB Output is correct
2 Correct 93 ms 41928 KB Output is correct
3 Correct 57 ms 21836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 14364 KB Output is correct
2 Correct 104 ms 49948 KB Output is correct
3 Correct 63 ms 24844 KB Output is correct
4 Correct 94 ms 47096 KB Output is correct