제출 #1340998

#제출 시각아이디문제언어결과실행 시간메모리
1340998doantaolaaidiCezar (COCI16_cezar)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define AC "test"
#define foru(i, l, r) for (int i = (l); i <= (r); i++)
#define ford(i, l, r) for (int i = (l); i >= (r); i--)
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vii;
typedef vector<ll> vll;

const ll inf = 1e9 + 7;
const ll linf = 1e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 7;
const int base = 31;

void fastIO(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

stack<int> topo;
ll n, res, visited[28], x, been[maxn], val[27];
vii g[105];
string t[105], s[105];

void dfs(int u){
    if (res == -1) return;
    visited[u] = 1;
    for (int v : g[u]){
        if (visited[v] == 1){
            res = -1;
            return;
        }
        if (!visited[v]) dfs(v);
        if (res == -1) return;
    }
    visited[u] = 2;
    topo.push(u);
}

void solve(){
    cin >> n;
    res = 0;
    foru(i,1,26){
        g[i].clear();
        visited[i] = 0;
    }
    while (!topo.empty()) topo.pop();
    memset(val, 0, sizeof(val));

    foru(i, 1 ,n){
        cin >> t[i];
    }
    foru(i, 1, n){
        cin >> x;
        s[i] = t[x];
    }
    foru(i, 1, n - 1){
        int found = 0;
        foru(k, 0, min(s[i].size(), s[i + 1].size()) - 1){
            if (s[i][k] != s[i + 1][k]){
                found = 1;
                g[s[i][k] - 'a' + 1].pb(s[i + 1][k] - 'a' + 1);
                break;
            }
        }
        if (!found && s[i].size() > s[i + 1].size()){
            cout << "NE";
            return;
        }
    }
    foru(i, 1, 26){
        if(!visited[i]) dfs(i);
    }s
    if (res == -1){
        cout << "NE";
        return;
    }
    cout << "DA\n";
    vector<int> order;
    while (!topo.empty()){
        order.pb(topo.top());
        topo.pop();
    }
    reverse(order.begin(), order.end());
    foru(i, 0, 25){
        val[order[i] - 1] = i;
    }
    foru(i, 0, 25){
        cout << char(val[i] + 'a');
    }
}

int main(){
    fastIO();
    if (fopen(AC".inp", "r")){
        freopen(AC".inp", "r", stdin);
        freopen(AC".out", "w", stdout);
    }
    solve();
}

컴파일 시 표준 에러 (stderr) 메시지

cezar.cpp: In function 'void solve()':
cezar.cpp:80:7: error: expected ';' before 'if'
   80 |     }s
      |       ^
      |       ;
   81 |     if (res == -1){
      |     ~~ 
cezar.cpp: In function 'int main()':
cezar.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen(AC".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
cezar.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen(AC".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~