#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define SZ(x) ((int) (x).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define F first
#define S second
#define left __left
#define right __right
#define prev __prev
#define next __next
template <class X, class Y>
bool maximize(X &x, Y y) {
if (x < y) return x = y, true;
else return false;
}
template <class X, class Y>
bool minimize(X &x, Y y) {
if (x > y) return x = y, true;
else return false;
}
#define MAX_N 150
int n;
vector <int> topo;
vector <int> adj[MAX_N + 2];
string word[MAX_N + 2];
int pos[MAX_N + 2];
int vis[MAX_N + 2];
void dfs(int u) {
vis[u] = 1;
for (int v : adj[u]) {
if (vis[v] == 0) dfs(v);
else if (vis[v] == 1) { /// check cycle;
cout << "NE";
exit(0);
}
}
vis[u] = 2;
topo.push_back(u);
}
int main() {
ios_base::sync_with_stdio(false);cin.tie(nullptr);
if (fopen("test.inp","r")) {
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
cin >> n;
FOR(i, 1, n) cin >> word[i];
FOR(i, 1, n) {
int x; cin >> x;
pos[x] = i;
}
/// this problem in oj.uz don't have checker;
FOR(i, 1, n) {
FOR(j, i + 1, n) {
bool ok = false;
REP(k, min(SZ(word[i]), SZ(word[j]))) {
char x = word[i][k], y = word[j][k];
if (x != y) {
if (pos[i] < pos[j]) adj[int(x)].push_back(int(y));
else adj[int(y)].push_back(int(x));
ok = true;
break;
}
}
if (!ok) {
if (SZ(word[i]) < SZ(word[j]) && pos[i] > pos[j]) return cout << "NE", 0;
if (SZ(word[i]) > SZ(word[j]) && pos[i] < pos[j]) return cout << "NE", 0;
}
}
}
memset(vis, 0, sizeof(vis));
FORD(i, 122, 97) if (vis[i] == 0) dfs(i);
cout << "DA\n";
reverse(ALL(topo));
vector <int> f(130, 0);
int cur = -1;
for (int x : topo) f[x] = ++cur;
FOR(i, 'a', 'z') cout << (char) (f[i] + 'a');
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
cezar.cpp: In function 'int main()':
cezar.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cezar.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |