제출 #534025

#제출 시각아이디문제언어결과실행 시간메모리
534025__VariattoType Printer (IOI08_printer)C++17
100 / 100
177 ms115288 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define ll long long const int A=30; const int MAX=25e3+10; struct st{ st* a[A]; int kon; }; int n; string s[MAX]; void stworz(st *v, char c){ if(v->a[c-'a']!=nullptr) return; st *nowy=new st; for(int i=0; i<A; i++) nowy->a[i]=nullptr; nowy->kon=0; v->a[c-'a']=nowy; } void dodaj(st* r, string s){ st *x=r; for(int i=0; i<s.size(); i++){ stworz(x, s[i]); x=x->a[s[i]-'a']; } x->kon++; } string ost; vector<char>wyn; void dfs(st* v, int j){ for(int i=1; i<=v->kon; i++) wyn.pb('P'); for(int i=0; i<A; i++){ if(i==ost[j]-'a') continue; if(v->a[i]!=nullptr){ wyn.pb(char(i+'a')); dfs(v->a[i], j+1); } } //return; if(j<ost.size() && v->a[ost[j]-'a']!=nullptr){ wyn.pb(ost[j]); dfs(v->a[ost[j]-'a'], j+1); } wyn.pb('-'); } int main(){ /* ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); */ cin>>n; st *r=new st; for(int i=0; i<A; i++) r->a[i]=nullptr; r->kon=0; pair<int,int> maxi={0,0}; for(int i=1; i<=n; i++){ cin>>s[i]; dodaj(r, s[i]); maxi=max(maxi, {int(s[i].size()), i}); } ost=s[maxi.se]; dfs(r, 0); while(wyn.size() && wyn.back()=='-') wyn.pop_back(); cout<<wyn.size()<<"\n"; for(auto x: wyn) cout<<x<<"\n"; }

컴파일 시 표준 에러 (stderr) 메시지

printer.cpp: In function 'void dodaj(st*, std::string)':
printer.cpp:26:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0; i<s.size(); i++){
      |                  ~^~~~~~~~~
printer.cpp: In function 'void dfs(st*, int)':
printer.cpp:46:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     if(j<ost.size() && v->a[ost[j]-'a']!=nullptr){
      |        ~^~~~~~~~~~~
#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...