답안 #91132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91132 2018-12-26T10:46:38 Z nikolapesic2802 Cezar (COCI16_cezar) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a))
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=26;
vector<vector<int> > graf(N);
int main()
{
	int n;
	scanf("%i",&n);
    vector<pair<int,string> > niz(n);
    for(int i=0;i<n;i++)
        cin >> niz[i].second;
    for(int i=0;i<n;i++)
        scanf("%i",&niz[i].first);
    sort(all(niz));
    for(int i=1;i<n;i++)
    {
        bool nasao=true;
        for(int j=0;j<min(niz[i].second.size(),niz[i-1].second.size());j++)
        {
            if(niz[i].s[j]!=niz[i-1].s[j])
            {
                graf[niz[i-1].s[j]-'a'].pb(niz[i].s[j]-'a');
                nasao=false;
                break;
            }
        }
        if(nasao)
        {
            if(niz[i].s.size()<niz[i-1].s.size())
            {
                printf("NE\n");
                return 0;
            }
        }
    }
    int tr=0;
    vector<int> degree(N);
    for(int i=0;i<N;i++)
    {
        for(auto p:graf[i])
        {
            degree[p]++;
        }
    }
    vector<int> sol(N);
    for(int i=0;i<N;i++)
    {
        bool ima=false;
        for(int j=0;j<N;j++)
        {
            if(degree[j]==0)
            {
                sol[j]=tr;
                tr++;
                ima=true;
                for(auto p:graf[j])
                {
                    degree[p]--;
                }
                degree[j]=INT_MAX;
                break;
            }
        }
        if(!ima)
        {
            printf("NE\n");
            return 0;
        }
    }
    printf("DA\n");
    for(int i=0;i<N;i++)
    {
        printf("%c",sol[i]+'a');
    }
    printf("\n");
    return 0;
}
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a))
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=26;
vector<vector<int> > graf(N);
int main()
{
	int n;
	scanf("%i",&n);
    vector<pair<int,string> > niz(n);
    for(int i=0;i<n;i++)
        cin >> niz[i].second;
    for(int i=0;i<n;i++)
        scanf("%i",&niz[i].first);
    sort(all(niz));
    for(int i=1;i<n;i++)
    {
        bool nasao=true;
        for(int j=0;j<min(niz[i].second.size(),niz[i-1].second.size());j++)
        {
            if(niz[i].s[j]!=niz[i-1].s[j])
            {
                graf[niz[i-1].s[j]-'a'].pb(niz[i].s[j]-'a');
                nasao=false;
                break;
            }
        }
        if(nasao)
        {
            if(niz[i].s.size()<niz[i-1].s.size())
            {
                printf("NE\n");
                return 0;
            }
        }
    }
    int tr=0;
    vector<int> degree(N);
    for(int i=0;i<N;i++)
    {
        for(auto p:graf[i])
        {
            degree[p]++;
        }
    }
    vector<int> sol(N);
    for(int i=0;i<N;i++)
    {
        bool ima=false;
        for(int j=0;j<N;j++)
        {
            if(degree[j]==0)
            {
                sol[j]=tr;
                tr++;
                ima=true;
                for(auto p:graf[j])
                {
                    degree[p]--;
                }
                degree[j]=INT_MAX;
                break;
            }
        }
        if(!ima)
        {
            printf("NE\n");
            return 0;
        }
    }
    printf("DA\n");
    for(int i=0;i<N;i++)
    {
        printf("%c",sol[i]+'a');
    }
    printf("\n");
    return 0;
}

Compilation message

cezar.cpp: In function 'int main()':
cezar.cpp:46:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<min(niz[i].second.size(),niz[i-1].second.size());j++)
                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cezar.cpp: At global scope:
cezar.cpp:124:39: error: redefinition of 'template<class T1, class T2> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)'
 template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
                                       ^~~~~~~~
cezar.cpp:19:39: note: 'template<class T1, class T2> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here
 template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
                                       ^~~~~~~~
cezar.cpp:125:28: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)'
 template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
                            ^~~~~~~~
cezar.cpp:20:28: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here
 template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
                            ^~~~~~~~
cezar.cpp:136:11: error: redefinition of 'const int N'
 const int N=26;
           ^
cezar.cpp:31:11: note: 'const int N' previously defined here
 const int N=26;
           ^
cezar.cpp:137:28: error: redefinition of 'std::vector<std::vector<int> > graf'
 vector<vector<int> > graf(N);
                            ^
cezar.cpp:32:22: note: 'std::vector<std::vector<int> > graf' previously declared here
 vector<vector<int> > graf(N);
                      ^~~~
cezar.cpp: In function 'int main()':
cezar.cpp:138:5: error: redefinition of 'int main()'
 int main()
     ^~~~
cezar.cpp:33:5: note: 'int main()' previously defined here
 int main()
     ^~~~
cezar.cpp:151:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<min(niz[i].second.size(),niz[i-1].second.size());j++)
                     ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
cezar.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&niz[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
cezar.cpp: In function 'int main()':
cezar.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
cezar.cpp:146:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i",&niz[i].first);
         ~~~~~^~~~~~~~~~~~~~~~~~~~