답안 #236596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236596 2020-06-02T14:29:25 Z nickmet2004 Type Printer (IOI08_printer) C++11
80 / 100
1000 ms 3700 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 25005;

int n;
int mx , P , cnt;
string MX;
char ans[45 * N];

struct word{char s[21];}Words[N];
bool operator<(const word& A , const word& B){
    int prA = 0, prB = 0 , As = strlen(A.s) , Bs = strlen(B.s);
    for(int i = 0; i < As; ++i){
        if(A.s[i] != MX[i]) break; ++prA;
    }
    for(int i = 0; i < Bs; ++i){
        if(B.s[i] != MX[i]) break; ++prB;
    }
    return prA < prB || prA == prB && strcmp(A.s , B.s) < 0;
}

int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> Words[i].s;
        if(strlen(Words[i].s)> mx){mx = strlen(Words[i].s); MX = Words[i].s;}
    }
    sort(Words , Words + n);
    string prev = Words[0].s;
    cnt += prev.size();
    for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;} ans[P] = 'P'; ++P;
    for(int i = 1; i < n; ++i){
        string cur = Words[i].s;
        int pr = 0;
        for(int k = 0; k < min(prev.size() , cur.size()); ++k){
            if(prev[k] != cur[k]) break; pr++;
        }
        cnt += prev.size() - pr; cnt += cur.size() - pr;
        for(int k = 1; k <= prev.size() - pr; ++k){ans[P] = '-'; ++P;}
        for(int k = pr; k < cur.size(); ++k){ans[P] = cur[k]; ++P;}
        ans[P] = 'P'; ++P;
        prev = cur;
    }
    cout << cnt + n << endl;
    for(int i = 0; i < P; ++i) cout << ans[i] << endl;
return 0;
}

Compilation message

printer.cpp: In function 'bool operator<(const word&, const word&)':
printer.cpp:16:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
         if(A.s[i] != MX[i]) break; ++prA;
         ^~
printer.cpp:16:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         if(A.s[i] != MX[i]) break; ++prA;
                                    ^~
printer.cpp:19:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
         if(B.s[i] != MX[i]) break; ++prB;
         ^~
printer.cpp:19:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
         if(B.s[i] != MX[i]) break; ++prB;
                                    ^~
printer.cpp:21:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
     return prA < prB || prA == prB && strcmp(A.s , B.s) < 0;
                         ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:30:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(strlen(Words[i].s)> mx){mx = strlen(Words[i].s); MX = Words[i].s;}
            ~~~~~~~~~~~~~~~~~~^~~~
printer.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;} ans[P] = 'P'; ++P;
                    ~~^~~~~~~~~~~~~
printer.cpp:39:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < min(prev.size() , cur.size()); ++k){
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:40:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
             if(prev[k] != cur[k]) break; pr++;
             ^~
printer.cpp:40:42: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
             if(prev[k] != cur[k]) break; pr++;
                                          ^~
printer.cpp:43:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 1; k <= prev.size() - pr; ++k){ans[P] = '-'; ++P;}
                        ~~^~~~~~~~~~~~~~~~~~~
printer.cpp:44:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = pr; k < cur.size(); ++k){ans[P] = cur[k]; ++P;}
                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 256 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 384 KB Output is correct
2 Correct 39 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 632 KB Output is correct
2 Correct 220 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 260 ms 1144 KB Output is correct
2 Correct 82 ms 888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 638 ms 2040 KB Output is correct
2 Execution timed out 1092 ms 3176 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 511 ms 2040 KB Output is correct
2 Execution timed out 1092 ms 3700 KB Time limit exceeded
3 Halted 0 ms 0 KB -