답안 #1004420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004420 2024-06-21T08:47:36 Z NoLove Type Printer (IOI08_printer) C++14
0 / 100
45 ms 38788 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 21-06-2024 
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int long long
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
using pii = pair<int, int>;
using vi = vector<int>;
#define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
void mx(int& a, int b) { if (b > a) a = b; }
void mi(int& a, int b) { if (b < a) a = b; }
#define si(x) (int)(x.size())
const int INF = 1e18;
const int MOD = 1e9 + 7;

const int MAXN = 1e6 + 5;
int g[MAXN];
int nxt[MAXN][28], d[MAXN], max_d[MAXN];
int n, sz = 0;

void insert(string& s) {
    int v = 0;
    for (char c : s) {
        if (!nxt[v][c - 'a']) nxt[v][c - 'a'] = ++sz;
        d[nxt[v][c - 'a']] = d[v] + 1;
        v = nxt[v][c - 'a'];
    }
    max_d[v] = d[v];
}

void dfs(int v) {
    int hi = -1;
    FOR(i, 0, 25) {
        if (nxt[v][i] && (hi == -1 or max_d[nxt[v][i]] > max_d[hi])) hi = i;
    }
    FOR(i, 0, 25) {
        if (nxt[v][i] && i != hi) {
            cout << (char)(i + 'a') << "\n";
            dfs(nxt[v][i]);
            if (n)
                cout << "-\n";
        }
    }

    if (hi == -1) cout << "P\n", n--;
    else {
        cout << (char)(hi + 'a') << "\n";
        dfs(nxt[v][hi]);
        if (n)
            cout << "-\n";
    }
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    } 

    string s;
    cin >> n;
    FOR(i, 1, n) {
        cin >> s;   
        insert(s);
    }
    
    for (int i = sz; i >= 0; i--) {
        FOR(c, 0, 25)
            if (nxt[i][c]) mx(max_d[i], max_d[nxt[i][c]]);
    }
    
    dfs(0);
}

Compilation message

printer.cpp: In function 'void dfs(long long int)':
printer.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
printer.cpp:42:5: note: in expansion of macro 'FOR'
   42 |     FOR(i, 0, 25) {
      |     ^~~
printer.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
printer.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i, 0, 25) {
      |     ^~~
printer.cpp: In function 'int32_t main()':
printer.cpp:18:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
printer.cpp:72:5: note: in expansion of macro 'FOR'
   72 |     FOR(i, 1, n) {
      |     ^~~
printer.cpp:18:31: warning: unnecessary parentheses in declaration of 'c' [-Wparentheses]
   18 | #define FOR(i, a, b) for (int (i) = a; (i) <= (b); i++)
      |                               ^
printer.cpp:78:9: note: in expansion of macro 'FOR'
   78 |         FOR(c, 0, 25)
      |         ^~~
printer.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 464 KB Expected integer, but "i" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1884 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 6236 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 15668 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 38788 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 30288 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -