Submission #83387

#TimeUsernameProblemLanguageResultExecution timeMemory
83387wjoaoCezar (COCI16_cezar)C++11
20 / 100
3 ms592 KiB
#include<bits/stdc++.h> #define maxn 500 using namespace std; string entrada[maxn], ordenado[maxn]; int n, ord[maxn], grau[maxn], atual = 'a', mark[maxn], impossivel; char encryption[maxn]; vector<int> g[maxn]; void dfs(int v, int cor){ //cout << "Dfs: " << (char)v << " cor: " << (char)cor << endl; mark[v] = cor; for(int i = 0; i < g[v].size(); i++){ int u = g[v][i]; if(mark[u] == cor){ impossivel = true; return; }else if(mark[u] == 0){ dfs(u, cor); } } encryption[v]=atual++; } int main(){ cin >> n; for(int i = 0; i < n; i++ ) cin >> entrada[i]; for(int i = 0; i < n; i++ ){ cin >> ord[i]; ord[i]--; ordenado[i] = entrada[ord[i]]; } //for(int i = 0; i < n; i++){ // cout << ordenado[i] << endl; //} for(int i = 1; i < n; i++){ int j = 0; while( j < ordenado[i].size() && j < ordenado[i-1].size() && ordenado[i][j] == ordenado[i-1][j] ) j++; if( j < ordenado[i].size() && j < ordenado[i-1].size()){ g[ordenado[i][j]].push_back(ordenado[i-1][j]); //cout << (char)ordenado[i][j] << " Tem que ser maior que: " << (char)ordenado[i-1][j] << endl; }else if( j == ordenado[i].size() && j < ordenado[i-1].size()){ impossivel = true; } } for(int i = 'a'; i <= 'z'; i++){ if(mark[i] == 0) dfs(i, i); } if(impossivel){ cout << "NE" << endl; }else{ cout << "DA" << endl; for(int i = 'a'; i <= 'z'; i++){ cout << encryption[i]; }cout << endl; } return 0; } //b->d->c /* 1 - bbb 2 - ccc c->b 2 - ccc => 3 - ddd d->c 3 - ddd 1 - bbb b->d 1 - ccc b->c 2 - ddd => c->d 3 - bbb d->b 2 3 1 */

Compilation message (stderr)

cezar.cpp: In function 'void dfs(int, int)':
cezar.cpp:15:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < g[v].size(); i++){
                  ~~^~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(  j < ordenado[i].size() && 
             ~~^~~~~~~~~~~~~~~~~~~~
cezar.cpp:41:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             j < ordenado[i-1].size() && 
             ~~^~~~~~~~~~~~~~~~~~~~~~
cezar.cpp:44:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if( j < ordenado[i].size() && j < ordenado[i-1].size()){
         ~~^~~~~~~~~~~~~~~~~~~~
cezar.cpp:44:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if( j < ordenado[i].size() && j < ordenado[i-1].size()){
                                   ~~^~~~~~~~~~~~~~~~~~~~~~
cezar.cpp:45:23: warning: array subscript has type 'char' [-Wchar-subscripts]
       g[ordenado[i][j]].push_back(ordenado[i-1][j]);
                       ^
cezar.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     }else if( j == ordenado[i].size() && j < ordenado[i-1].size()){
               ~~^~~~~~~~~~~~~~~~~~~~~
cezar.cpp:47:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     }else if( j == ordenado[i].size() && j < ordenado[i-1].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...