답안 #716630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
716630 2023-03-30T15:28:49 Z europium Type Printer (IOI08_printer) C++17
20 / 100
37 ms 3572 KB
// - 28/3/23
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <iterator>
#include <set>
#include <map>
#include <math.h>
#include <iomanip>
#include <unordered_set>
#include <queue>
#include <climits>
using namespace std;
// clang++ -std=c++17 IOI08_Printer.cpp && ./a.out

using ll = long long;

void solve(){
    int n;
    cin >> n;

    vector<string> a(n);
    for (string& e : a) cin >> e;

    int max_len = 0;
    char end_ltr;

    for (auto e : a){
        if (e.size() > max_len){
            max_len = e.size();
            end_ltr = e[0];
        }
    }

    vector<string> first, last;

    for (auto e : a){
        if (e[0] == end_ltr) last.push_back(e);
        else first.push_back(e);
    }

    sort(first.begin(), first.end());
    sort(last.begin(), last.end());

    a.clear();

    for (auto e : first) a.push_back(e);
    for (auto e : last) a.push_back(e);

    vector<char> ans;

    string s = "";

    for (auto e : a){
        // removing characters
        int stop;

        for (int i = 0; i < min(s.size(), e.size()); i++){
            if (s[i] != e[i]){
                stop = i;
                break;
            }
        }

        for (int i = 0; i < s.size() - stop; i++) ans.push_back('-');
        s = s.substr(0, stop);

        // adding characters
        while (s != e){
            ans.push_back(e[s.size()]);
            s += e[s.size()];
        }
        ans.push_back('P');
    }

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

    for (auto e : ans) cout << e << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    // freopen("input.txt", "r", stdin);
    solve();

    return 0;
}

Compilation message

printer.cpp: In function 'void solve()':
printer.cpp:32:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |         if (e.size() > max_len){
      |             ~~~~~~~~~^~~~~~~~~
printer.cpp:61:27: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   61 |         for (int i = 0; i < min(s.size(), e.size()); i++){
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:68:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |         for (int i = 0; i < s.size() - stop; i++) ans.push_back('-');
      |                         ~~^~~~~~~~~~~~~~~~~
printer.cpp:68:40: warning: 'stop' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |         for (int i = 0; i < s.size() - stop; i++) ans.push_back('-');
      |                                        ^~~~
printer.cpp:41:9: warning: 'end_ltr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         if (e[0] == end_ltr) last.push_back(e);
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 3572 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 3392 KB Output isn't correct
2 Halted 0 ms 0 KB -