답안 #953540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953540 2024-03-26T05:55:27 Z DarkKnight101 Type Printer (IOI08_printer) C++17
100 / 100
100 ms 93132 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
 
#define endl "\n"
#define aint(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define forl(i,n) for(int i=0;i<n;i++)

const ll WMAX = 5e5+5;
const ll MOD = 1e9 + 7;

ll trie[WMAX][26];
ll node_count;
bool stop[WMAX];

/** Adds a new word into the trie. */
void insert_word(string& word) {
	// Node 0 has 26 children - a through z.
	ll node = 0;
	for (char c : word) {
		// If a node with the current char doesn't exist create one.
		if (trie[node][c - 'a'] == 0) { trie[node][c - 'a'] = ++node_count; }
		// Move down the path in the trie.
		node = trie[node][c - 'a'];
	}
	// Mark the ending node so we know it's a dictionary word
	stop[node] = true;
}

vector<char>ans;
string big;
ll mx =0;

void fun(ll node,ll depth){
    ll curr = big[depth]-'a';
    curr++;
    if(depth>=mx) return;
    forl(i,26){
        if(trie[node][(i+curr)%26]){
            ans.pb(97+((i+curr)%26));
            
        
            if(stop[trie[node][(i+curr)%26]]) {
                ans.pb('P');
            }
            
            fun(trie[node][(i+curr)%26],depth+1);
            ans.pb(45);
        }
    }
}



void solve(){
    ll n;
    cin >> n;
    string s;
    mx=0;
    
    forl(i,n){
        cin >> s;
        if(s.length()>mx){
            big = s;
            mx= s.length();
        }
        insert_word(s);
    }
    fun(0,0);
    while(ans.back()==45) ans.pop_back();
    cout << ans.size() << endl;
    for(auto i:ans) cout << i << endl;


}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt=1;
    // cin >> tt;
    while (tt--){
        solve();
    }
}

Compilation message

printer.cpp: In function 'void solve()':
printer.cpp:68:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   68 |         if(s.length()>mx){
      |            ~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5720 KB Output is correct
2 Correct 13 ms 11864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 13792 KB Output is correct
2 Correct 6 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 34256 KB Output is correct
2 Correct 87 ms 78032 KB Output is correct
3 Correct 47 ms 40144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 26840 KB Output is correct
2 Correct 100 ms 93132 KB Output is correct
3 Correct 55 ms 45916 KB Output is correct
4 Correct 91 ms 88008 KB Output is correct