Submission #165668

#TimeUsernameProblemLanguageResultExecution timeMemory
165668egekabasCezar (COCI16_cezar)C++14
20 / 100
2 ms380 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<ll, ll> pii; typedef pair<ld, ld> pld; ll n; string s1[109]; string s2[109]; ll a[109]; vector<ll> g[109]; ll inc[109]; ll vis[109]; vector<int> ans; pll dif(string t1, string t2){ for(int i = 0; i < min(t1.size(), t2.size()); ++i) if(t1[i] != t2[i]){ return {t1[i]-'a', t2[i]-'a'}; } if(t2.size() < t1.size()){ cout << "NE\n"; exit(0); } else{ return {-1, -1}; } } void dfs(ll v){ vis[v] = 1; ans.pb(v); for(auto u : g[v]){ if(vis[u] == 1) continue; --inc[u]; if(inc[u] == 0) dfs(u); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n; for(int i = 0; i < n; ++i) cin >> s1[i]; for(int i = 0; i < n; ++i){ cin >> a[i]; --a[i]; s2[a[i]] = s1[i]; } for(ll i = 0; i < n-1; ++i){ pll tmp = dif(s2[i], s2[i+1]); if(tmp.ff == -1) continue; g[tmp.ff].pb(tmp.ss); ++inc[tmp.ss]; } for(ll i = 0; i <= 'z'-'a'; ++i){ if(inc[i] == 0 && vis[i] == 0) dfs(i); } for(ll i = 0; i <= 'z'-'a'; ++i){ if(vis[i] == 0){ cout << "NE\n"; return 0; } } cout << "DA\n"; for(auto u : ans) cout << (char)(u+'a'); }

Compilation message (stderr)

cezar.cpp: In function 'pll dif(std::__cxx11::string, std::__cxx11::string)':
cezar.cpp:23:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < min(t1.size(), t2.size()); ++i)
                    ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...