# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
133393 | 2019-07-20T13:55:42 Z | tdwn | Cezar (COCI16_cezar) | C++17 | 3 ms | 376 KB |
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair using namespace std; const int maxn = 110; string tempstr[maxn]; string str[maxn]; int perm[maxn], n; vector<int>g[30], rg[30]; int visited[maxn]; vector<int>order; bool cycle; void dfs(int node) { if(visited[node] == 2) return; if(visited[node] == 1) { visited[node] = 2; cycle = true; return; } visited[node] = 1; for(int i:g[node]) { if(visited[i] == 0) { dfs(i); } else if(visited[i] == 1) { cycle = true; } } visited[node] = 2; order.pb(node); } int main() { cin>>n; for(int i=1;i<=n;i++) { cin>>tempstr[i]; } for(int i=1;i<=n;i++) { cin>>perm[i]; } for(int i=1;i<=n;i++) { str[perm[i]] = tempstr[i]; } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { if(str[j].length() < str[i].length()) { if(str[i].substr(0, str[j].length()) == str[j]) { cout<<"NE\n"; return 0; } } } } for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { for(int k=0;k<min(int(str[i].length()), int(str[j].length()));k++) { if(str[i][k] != str[j][k]) { g[int(str[i][k]-'a')].pb(int(str[j][k]-'a')); } } } } for(int i=0;i<26;i++) { if(visited[i] == 0) dfs(i); } if(cycle) { cout<<"NE\n"; return 0; } cout<<"DA\n"; reverse(order.begin(), order.end()); for(int i=0;i<order.size();i++) { cout<<char(order[i]+'a'); } }
Compilation message
# | 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 | 2 ms | 256 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 | 256 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 | - |
# | 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 | 1 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 252 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |