# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
165667 | 2019-11-28T07:09:05 Z | egekabas | Cezar (COCI16_cezar) | C++14 | 3 ms | 504 KB |
#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]; ll used[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]; used[tmp.ff] = 1; used[tmp.ss] = 1; } for(ll i = 0; i <= 'z'-'a'; ++i){ if(inc[i] == 0 && vis[i] == 0 && used[i] == 1) dfs(i); } for(ll i = 0; i <= 'z'-'a'; ++i){ if(used[i] == 1 && vis[i] == 0){ cout << "NE\n"; exit(0); } if(used[i] == 0) ans.pb(i); } cout << "DA\n"; for(auto u : ans) cout << (char)(u+'a'); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 504 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 1 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |