Submission #1016602

#TimeUsernameProblemLanguageResultExecution timeMemory
1016602NintsiChkhaidzeType Printer (IOI08_printer)C++17
100 / 100
930 ms58160 KiB
#include <bits/stdc++.h> #define pb push_back #define s second #define f first #define pb push_back #define pii pair <int,int> #define ll long long #define left h*2,l,(l + r)/2 #define right h*2+1,(l + r)/2 + 1,r // #define int ll using namespace std; const int N = 3e5 + 5; int lenmx,cnt = 1; bool fin[500005]; string s[N],str; map <int,int> mp[500005]; vector <char> ans; void add(string x){ int root = 1; for (int i = 0; i < x.size(); i++){ int b = (x[i] - 'a' + 1); if (mp[root].find(b) == mp[root].end()){ mp[root][b] = ++cnt; } root = mp[root][b]; } fin[root] = 1; } void dfs(int x,int i,bool eq){ if (fin[x]) ans.pb('P'); if (eq == 1 && i == str.size()) { cout<<ans.size()<<endl; for (auto c: ans) cout<<c<<endl; exit(0); } int b = (str[i] - 'a' + 1); for (int j = 1; j <= 26; j++){ if (mp[x].find(j) == mp[x].end()) continue; if (j != b || (j == b && !eq)){ ans.pb(char(j + 'a' - 1)); dfs(mp[x][j],i + 1,0); } } if (eq) { ans.pb(char(b + 'a' - 1)); dfs(mp[x][b],i + 1,1); } ans.pb('-'); } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; for (int i = 1; i <= n; i++){ cin >> s[i]; add(s[i]); int len = s[i].size(); if (len > lenmx){ str = s[i]; lenmx = len; } } dfs(1,0,1); }

Compilation message (stderr)

printer.cpp: In function 'void add(std::string)':
printer.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < x.size(); i++){
      |                  ~~^~~~~~~~~~
printer.cpp: In function 'void dfs(int, int, bool)':
printer.cpp:38:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  if (eq == 1 && i == str.size()) {
      |                 ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...