Submission #165684

#TimeUsernameProblemLanguageResultExecution timeMemory
165684egekabasCezar (COCI16_cezar)C++14
0 / 100
3 ms376 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 vis[109]; map<pll, ll> mpp; vector<ll> 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; for(auto u : g[v]){ if(vis[u] == 1) continue; dfs(u); } ans.pb(v); } void check(ll v){ vis[v] = 2; for(auto u : g[v]){ if(vis[u] == 1) continue; if(vis[u] == 2){ cout << "NE\n"; exit(0); } check(u); } vis[v] = 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); cin >> n; for(ll i = 0; i < n; ++i) cin >> s1[i]; for(ll 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 || mpp[tmp] == 1) continue; mpp[tmp] = 1; g[tmp.ff].pb(tmp.ss); } for(ll i = 0; i <= 'z'-'a'; ++i) if(vis[i] == 0) check(i); for(ll i = 0; i <= 'z'-'a'; ++i) vis[i] = 0; for(ll i = 0; i <= 'z'-'a'; ++i){ if(vis[i] == 0) dfs(i); } cout << "DA\n"; reverse(ans.begin(), ans.end()); 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...