Submission #53688

# Submission time Handle Problem Language Result Execution time Memory
53688 2018-07-01T04:44:35 Z 강태규(#1435) Type Printer (IOI08_printer) C++11
100 / 100
79 ms 6668 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

const char inf = 'z' + 1;
int n;
struct str {
    char s[30];
    void scan() {
        scanf("%s", s);
    }
    bool operator<(const str &p) const {
        return strcmp(s, p.s) > 0;
    }
} s[25000];

vector<char> q;

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        s[i].scan();
    }
    int mn = min_element(s, s + n, [&](const str &x, const str &y) {
        return strlen(x.s) > strlen(y.s);
    }) - s;
    swap(s[0], s[mn]);
    for (int i = 1; i < n; ++i) {
        for (int j = 0; s[i].s[j]; ++j) {
            if (s[0].s[j] == s[i].s[j]) s[i].s[j] = inf;
        }
    }
    sort(s + 1, s + n);
    char t[30] = "", p = 0;
    for (int i = n; i--; ) {
        for (int j = 0; s[i].s[j]; ++j) {
            if (s[i].s[j] == inf) s[i].s[j] = s[0].s[j];
        }
        for (int j = 0; j < p; ++j) {
            if (s[i].s[j] != t[j]) {
                while (j < p) {
                    q.push_back('-');
                    --p;
                }
                break;
            }
        }
        for (int j = p; s[i].s[j]; ++j) {
            q.push_back(t[p++] = s[i].s[j]);
        }
        q.push_back('P');
    }
    printf("%d\n", (int)q.size());
    for (char c : q) {
        printf("%c\n", c);
    }
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:65:30: warning: array subscript has type 'char' [-Wchar-subscripts]
             q.push_back(t[p++] = s[i].s[j]);
                              ^
printer.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
printer.cpp: In member function 'void str::scan()':
printer.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", s);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 440 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 556 KB Output is correct
2 Correct 3 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 708 KB Output is correct
2 Correct 2 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 708 KB Output is correct
2 Correct 4 ms 708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 836 KB Output is correct
2 Correct 5 ms 840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 996 KB Output is correct
2 Correct 19 ms 1380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1592 KB Output is correct
2 Correct 15 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 2504 KB Output is correct
2 Correct 61 ms 4424 KB Output is correct
3 Correct 38 ms 4424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 4424 KB Output is correct
2 Correct 79 ms 5748 KB Output is correct
3 Correct 51 ms 5748 KB Output is correct
4 Correct 73 ms 6668 KB Output is correct