# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
170475 | mdn2002 | Cezar (COCI16_cezar) | C++14 | 1086 ms | 504 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int n,vis[39];
vector<int>gr[40];
vector<string>v,a;
string s;
void ckl(int x)
{
vis[x]=1;
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i];
if(vis[u]==1)
{
cout<<"NE";
exit(0);
}
else if(vis[u]==0)ckl(u);
}
vis[x]=2;
}
void dfs(int x)
{
vis[x-1]=1;
s.push_back((x+'a')-1);
for(int i=0;i<gr[x].size();i++)
{
int u=gr[x][i];
if(vis[u-1])continue;
dfs(u);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen("lemonade.in","r",stdin);
//freopen("lemonade.out","w",stdout);
cin>>n;
for(int i=0;i<n;i++)
{
string s;
cin>>s;
v.push_back(s);
}
for(int i=0;i<n;i++)
{
int x;
cin>>x;
a.push_back(v[x-1]);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i].size()!=a[j].size())
{
int x=0;
while(true)x++;
}
for(int z=0;z<a[i].size();z++)
{
if(a[i][z]!=a[j][z])
{
gr[(a[i][z]-'a')+1].push_back((a[j][z]-'a')+1);
break;
}
}
}
}
for(int i=1;i<=30;i++)
{
if(vis[i]==0)ckl(i);
}
memset(vis,0,sizeof vis);
for(int i=0;i<n;i++)
{
for(int j=0;j<a[i].size();j++)
{
if(vis[(a[i][j]-'a')]==0)dfs((a[i][j]-'a')+1);
}
}
for(int i=0;i<='z'-'a';i++)
{
if(vis[i]==0)s.push_back(i+'a');
}
cout<<"DA"<<endl<<s;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |