# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98263 | 2019-02-21T18:02:13 Z | dalgerok | Cezar (COCI16_cezar) | C++17 | 3 ms | 512 KB |
#include<bits/stdc++.h> using namespace std; const int N = 105, M = 26; int n, cl[N]; int a[M][M], in[M]; string s[N], t[N]; vector < int > g[N], order; char ans[M]; void dfs1(int v){ cl[v] = 1; for(int to = 0; to < M; to++){ if(a[v][to]){ if(cl[to] == 0){ dfs1(to); } else if(cl[to] == 1){ cout << "NE"; exit(0); } } } cl[v] = 2; } void dfs2(int v){ cl[v] = 1; for(int to = 0; to < M; to++){ if(a[v][to] && !cl[to]){ dfs2(to); } } order.push_back(v); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> s[i]; for(auto &it : s[i]){ it -= 'a'; } } for(int i = 1; i <= n; i++){ int x; cin >> x; t[i] = s[x]; } for(int i = 1; i <= n; i++){ for(int j = 1; j < i; j++){ if((int)t[i].size() < (int)t[j].size() && t[j].substr(0, (int)t[i].size()) == t[i]){ return cout << "NE", 0; } } } for(int i = 2; i <= n; i++){ for(int j = 0; j < min((int)t[i - 1].size(), (int)t[i].size()); j++){ if(t[i - 1][j] != t[i][j]){ if(a[t[i][j]][t[i - 1][j]] == 0){ a[t[i][j]][t[i - 1][j]] = 1; in[t[i - 1][j]] += 1; } break; } } } for(int i = 1; i <= n; i++){ if(cl[i] == 0){ dfs1(i); } } memset(cl, 0, sizeof(cl)); for(int i = 0; i < M; i++){ if(in[i] == 0){ dfs2(i); } } for(int i = 0; i < M; i++){ ans[order[i]] = i; } cout << "DA\n"; for(int i = 0; i < M; i++){ cout << char(ans[i] + 'a'); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 3 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 384 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |