답안 #349254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349254 2021-01-17T09:15:42 Z jenny00513 Type Printer (IOI08_printer) C++14
10 / 100
44 ms 3432 KB
#include <bits/stdc++.h>
using namespace std;

int n;
string st;
string s[25005];
vector<char> print;
vector<string> last;
string nvr = "This should not be printed!";

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> s[i];

    sort(s + 1, s + n + 1);

    char start = NULL; int mx = 0;
    int pos;

    for (int i = 1; i <= n; i++)
    {
        if (s[i].size() > mx)
        {
            start = (char)s[i][0], mx = s[i].size();
            pos = i;
        }
    }

    int ss = -1, ee = -1;

    for (int i = 1; i <= n; i++)
    {
        if (ss == -1 && (char)s[i][0] == start)
            ss = i;

        if (ee == -1 && ((char)s[i + 1][0] != start || i == n))
        {
            ee = i;
            break;
        }
    }

    for (int i = ss; i <= pos; i++)
    {
        last.push_back(s[i]);
        s[i] = nvr;
    }

    for (int i = 1; i <= n; i++)
    {
        if ((char)s[i][0] == start)
            continue;

        if (s[i] == nvr)
            continue;

        while (true)
        {
            if (st == s[i].substr(0, st.size()))
                break;

            st = st.substr(0, (int)st.size() - 1);
            print.push_back('-');
        }

        for (int k = st.size(); k < s[i].size(); k++)
            print.push_back((char)s[i][k]);

        print.push_back('P');

        st = s[i];
    }

    for (int i = 1; i <= n; i++)
    {
        if ((char)s[i][0] != start)
            continue;

        if (s[i] == nvr)
            continue;

        while (true)
        {
            if (st == s[i].substr(0, st.size()))
                break;

            st = st.substr(0, (int)st.size() - 1);
            print.push_back('-');
        }

        for (int k = st.size(); k < s[i].size(); k++)
            print.push_back((char)s[i][k]);

        print.push_back('P');

        st = s[i];
    }

    for (int i = 0; i < last.size(); i++)
    {
        while (true)
        {
            if (st == last[i].substr(0, st.size()))
                break;

            st = st.substr(0, (int)st.size() - 1);
            print.push_back('-');
        }

        for (int k = st.size(); k < last[i].size(); k++)
            print.push_back((char)last[i][k]);

        print.push_back('P');

        st = last[i];
    }

    cout << print.size() << '\n';

    for (char each : print)
        cout << each << '\n';

    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:23:18: warning: converting to non-pointer type 'char' from NULL [-Wconversion-null]
   23 |     char start = NULL; int mx = 0;
      |                  ^~~~
printer.cpp:28:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |         if (s[i].size() > mx)
      |             ~~~~~~~~~~~~^~~~
printer.cpp:72:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         for (int k = st.size(); k < s[i].size(); k++)
      |                                 ~~^~~~~~~~~~~~~
printer.cpp:97:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |         for (int k = st.size(); k < s[i].size(); k++)
      |                                 ~~^~~~~~~~~~~~~
printer.cpp:105:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  105 |     for (int i = 0; i < last.size(); i++)
      |                     ~~^~~~~~~~~~~~~
printer.cpp:116:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |         for (int k = st.size(); k < last[i].size(); k++)
      |                                 ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1132 KB Output is correct
2 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 2156 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2156 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2156 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2156 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 2284 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2540 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 3432 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 2532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 2920 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -