Submission #1091674

#TimeUsernameProblemLanguageResultExecution timeMemory
1091674vjudge1Cezar (COCI16_cezar)C++17
40 / 100
1 ms600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() #define forn(i,a,b) for(int i = a; i < b; i++) const int MAXN = 100; const int MAXL = 26; struct Word{ string str; ll ord; Word(ll ord, string str) : ord(ord), str(str) {} }; bool cmp(const Word &a, const Word &b) { if(a.ord<b.ord) return true; return false; } ll n; string strs[MAXN]; ll ord[MAXN]; bool menor[MAXL][MAXL]; // menor[i][j] = true -> si i < j int main(){ cin>>n; forn(i,0,n) cin>>strs[i]; forn(i,0,n) cin>>ord[i]; vector<Word> sorted; forn(i,0,n) sorted.pb(Word(i,strs[ord[i]-1])); sort(ALL(sorted),cmp); forn(i,0,n){ forn(j,i+1,n){ string a,b; a = sorted[i].str; b = sorted[j].str; //cout<<a<<" "<<b<<'\n'; forn(h,0,SZ(a)){ if(h>=SZ(b)){ cout<<"NE\n"; return 0; } if(a[h]==b[h]) continue; menor[a[h]-'a'][b[h]-'a']=true; //cout<<a[h]<<" "<<b[h]<<'\n'; if(menor[b[h]-'a'][a[h]-'a']){ cout<<"NE\n"; return 0; } break; } } } vector<bool> used(MAXL,false); vector<char> dicc(MAXL); forn(i,0,MAXL){ forn(j,0,MAXL){ bool puede = true; if(used[j]) puede = false; forn(h,0,MAXL){ if(menor[h][j]) puede = false; } if(puede){ dicc[j]=i+'a'; used[j]=true; forn(h,0,MAXL){menor[j][h]=false;} break; } else if(!used[j]){ //cout<<j<<" no pudo en "<<i<<'\n'; } } } cout<<"DA\n"; forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n'; return 0; }

Compilation message (stderr)

cezar.cpp: In constructor 'Word::Word(ll, std::string)':
cezar.cpp:17:5: warning: 'Word::ord' will be initialized after [-Wreorder]
   17 |  ll ord;
      |     ^~~
cezar.cpp:16:9: warning:   'std::string Word::str' [-Wreorder]
   16 |  string str;
      |         ^~~
cezar.cpp:18:2: warning:   when initialized here [-Wreorder]
   18 |  Word(ll ord, string str) : ord(ord), str(str) {}
      |  ^~~~
cezar.cpp: In function 'int main()':
cezar.cpp:10:21: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   10 | #define forn(i,a,b) for(int i = a; i < b; i++)
      |                     ^~~
cezar.cpp:79:2: note: in expansion of macro 'forn'
   79 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |  ^~~~
cezar.cpp:79:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   79 |  forn(i,0,SZ(dicc)) cout<<dicc[i]; cout<<'\n';
      |                                    ^~~~
#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...