답안 #337975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337975 2020-12-22T08:29:48 Z jainbot27 Type Printer (IOI08_printer) C++17
100 / 100
83 ms 7588 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 25001;

string word[mxN];
int n, maxi, maxs;
pair<pair<int, string>, int> v[mxN];
string lst = "";
string res;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i < n; i++) {
        cin >> word[i];
        if(word[i].size() > maxs)
            maxs=word[i].size(), maxi=i;
    }
    for(int i=0; i < n; i++){
        int cnt=0;
        for(int j = 0; j < word[i].size(); j++){
            if(word[i][j]!=word[maxi][j]) break;
            cnt++;
        }
        v[i]={{cnt, word[i]}, i};
    }
    sort(v, v+ n);
    for(int i=0; i < n; i++){
        string cur = v[i].first.second;
        int cnt = 0;
        for(int j =0; j < min(cur.size(), lst.size()); j++){
            if(lst[j]!=cur[j]) break;
            cnt++;
        }
        for(int j =0; j < lst.size() - cnt; j++)  res += '-';
        for(int j = cnt; j < cur.size(); j++) res += (cur[j]);
        res+='P';
        lst=cur;
    }
    cout << res.size() << "\n";
    for(int i = 0; i < res.size(); i++) cout << res[i] << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:17:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   17 |         if(word[i].size() > maxs)
      |            ~~~~~~~~~~~~~~~^~~~~~
printer.cpp:22:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int j = 0; j < word[i].size(); j++){
      |                        ~~^~~~~~~~~~~~~~~~
printer.cpp:32:25: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   32 |         for(int j =0; j < min(cur.size(), lst.size()); j++){
      |                       ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:36:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j =0; j < lst.size() - cnt; j++)  res += '-';
      |                       ~~^~~~~~~~~~~~~~~~~~
printer.cpp:37:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int j = cnt; j < cur.size(); j++) res += (cur[j]);
      |                          ~~^~~~~~~~~~~~
printer.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for(int i = 0; i < res.size(); i++) cout << res[i] << '\n';
      |                    ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2284 KB Output is correct
2 Correct 2 ms 2284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2284 KB Output is correct
2 Correct 3 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2412 KB Output is correct
2 Correct 4 ms 2412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2540 KB Output is correct
2 Correct 14 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2940 KB Output is correct
2 Correct 13 ms 2924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 4112 KB Output is correct
2 Correct 70 ms 6824 KB Output is correct
3 Correct 45 ms 5768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 3464 KB Output is correct
2 Correct 83 ms 7588 KB Output is correct
3 Correct 51 ms 6280 KB Output is correct
4 Correct 74 ms 7460 KB Output is correct