# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
165693 |
2019-11-28T10:16:58 Z |
egekabas |
Cezar (COCI16_cezar) |
C++14 |
|
2 ms |
392 KB |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n;
string s1[109];
string s2[109];
ll a[109];
vector<ll> g[109];
ll vis[109];
map<pll, ll> mpp;
vector<ll> ans;
pll dif(string t1, string t2){
for(int i = 0; i < min(t1.size(), t2.size()); ++i)
if(t1[i] != t2[i]){
return {t1[i]-'a', t2[i]-'a'};
}
return {-1, -1};
}
void dfs(ll v){
vis[v] = 1;
for(auto u : g[v]){
if(vis[u] == 1)
continue;
dfs(u);
}
ans.pb(v);
}
void check(ll v){
vis[v] = 2;
for(auto u : g[v]){
if(vis[u] == 1)
continue;
if(vis[u] == 2){
cout << "NE\n";
exit(0);
}
check(u);
}
vis[v] = 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
for(ll i = 0; i < n; ++i)
cin >> s1[i];
for(ll i = 0; i < n; ++i){
cin >> a[i];
--a[i];
s2[a[i]] = s1[i];
}
for(ll i = 0; i < n-1; ++i){
pll tmp = dif(s2[i], s2[i+1]);
if(tmp.ff == -1 || mpp[tmp] == 1)
continue;
mpp[tmp] = 1;
g[tmp.ff].pb(tmp.ss);
}
for(ll i = 0; i <= 'z'-'a'; ++i)
if(vis[i] == 0)
check(i);
for(ll i = 0; i <= 'z'-'a'; ++i)
vis[i] = 0;
for(ll i = 0; i <= 'z'-'a'; ++i){
if(vis[i] == 0)
dfs(i);
}
cout << "DA\n";
reverse(ans.begin(), ans.end());
for(auto u : ans)
cout << (char)(u+'a');
}
Compilation message
cezar.cpp: In function 'pll dif(std::__cxx11::string, std::__cxx11::string)':
cezar.cpp:23:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < min(t1.size(), t2.size()); ++i)
~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
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 |
392 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 |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |