# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91161 | nikolapesic2802 | Cezar (COCI16_cezar) | C++14 | 3 ms | 688 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>
#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<string> niz(n);
vector<string> prvo(n);
for(int i=0;i<n;i++)
cin >> prvo[i];
for(int i=0;i<n;i++)
{
int x;
scanf("%i",&x);
x--;
niz[i]=prvo[x];
}
for(int i=0;i<n;i++)
cout << niz[i] << endl;
for(int i=1;i<n;i++)
{
for(int j=0;j<i;j++)
{
int si=niz[i].size();
int sj=niz[j].size();
if(si<sj)
{
if(niz[j].substr(0,si)==niz[i])
{
printf("NE\n");
return 0;
}
}
}
}
for(int i=1;i<n;i++)
{
bool nasao=true;
for(int j=0;j<min(niz[i].size(),niz[i-1].size());j++)
{
if(niz[i][j]!=niz[i-1][j])
{
graf[niz[i-1][j]-'a'].pb(niz[i][j]-'a');
//printf("%i->%i\n",niz[i-1][j]-'a',niz[i][j]-'a');
nasao=false;
break;
}
}
if(nasao)
{
if(niz[i].size()<niz[i-1].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,-1);
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 (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... |