# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
165671 |
2019-11-28T07:49:35 Z |
egekabas |
Cezar (COCI16_cezar) |
C++14 |
|
4 ms |
376 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 inc[109];
ll vis[109];
map<pll, ll> mpp;
vector<int> 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'};
}
if(t2.size() < t1.size()){
cout << "NE\n";
exit(0);
}
else{
return {-1, -1};
}
}
void dfs(ll v){
vis[v] = 1;
ans.pb(v);
for(auto u : g[v]){
if(vis[u] == 1)
continue;
--inc[u];
if(inc[u] == 0)
dfs(u);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n;
for(int i = 0; i < n; ++i)
cin >> s1[i];
for(int 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);
++inc[tmp.ss];
}
for(ll i = 0; i <= 'z'-'a'; ++i){
if(inc[i] == 0 && vis[i] == 0)
dfs(i);
}
for(ll i = 0; i <= 'z'-'a'; ++i){
if(vis[i] == 0){
cout << "NE\n";
return 0;
}
}
cout << "DA\n";
for(auto u : ans)
cout << (char)(u+'a');
}
Compilation message
cezar.cpp: In function 'pll dif(std::__cxx11::string, std::__cxx11::string)':
cezar.cpp:24: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 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
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 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
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 |
- |