답안 #170485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170485 2019-12-25T12:04:52 Z mdn2002 Cezar (COCI16_cezar) C++14
0 / 100
3 ms 380 KB
#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++)
        {
            for(int z=0;z<min(a[i].size(),a[j].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=i+1;j<n;j++)
        {
            for(int z=0;z<min(a[i].size(),a[j].size());z++)
            {
                if(a[i][z]!=a[j][z])
                {
                    if(vis[a[i][z]-'a']==0)dfs((a[i][z]-'a')+1);
                    break;
                }
            }
        }
    }
    for(int i=0;i<='z'-'a';i++)
    {
        if(vis[i]==0)s.push_back(i+'a');
    }
    cout<<"DA"<<endl<<s<<endl;
}
/*
5
aaaaaaaaaaa
aaaaaaaaaab
aaaaaaaaaac
aaaaaaaaaad
aaaaaaaaaae
5 4 3 2 1
*/

Compilation message

cezar.cpp: In function 'void ckl(int)':
cezar.cpp:11:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
cezar.cpp: In function 'void dfs(int)':
cezar.cpp:27:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<gr[x].size();i++)
                 ~^~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:58:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int z=0;z<min(a[i].size(),a[j].size());z++)
                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cezar.cpp:78:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int z=0;z<min(a[i].size(),a[j].size());z++)
                         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -